[Python] Python Code to combine duplicated element

Discussão em 'Python' iniciado por Stack, Janeiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a list with duplicated some of element. And i need to combine some element based on the other duplicated element.

    Example input:

    [
    ('Sig: 7126', '10.3.5.0', 4),
    ('Sig: 7126', '10.3.5.0', 1),
    ('Sig: 7126', '10.3.5.0', 1),
    ('Sig: 3326', '10.3.5.0', 7),
    ('Sig: 7126', '10.3.5.1', 3),
    ('Sig: 7126', '10.3.5.1', 1),
    ('Sig: 7126', '10.3.5.2', 5),
    ('Sig: 7126', '10.3.5.2', 1),
    ('Sig: 7126', '10.3.5.4', 2),
    ('Sig: 7126', '10.3.5.4', 1),
    ('Sig: 7126', '10.3.5.4', 1),
    ('Sig: 7126', '10.3.5.4', 1),
    ('Sig: 0559', '10.3.5.34', 1),
    ('Sig: 7126', '10.3.5.34', 1),
    ('Sig: 7126', '10.3.5.34', 1),
    ('Sig: 0559', '10.3.5.42', 1),
    ('Sig: 7126', '10.3.5.42', 1),
    ('Sig: 7126', '10.3.5.43', 2)
    ]


    What the goal is like this:

    [
    ('Sig: 7126', '10.3.5.0', 6),
    ('Sig: 3326', '10.3.5.0', 7),
    ('Sig: 7126', '10.3.5.1', 4),
    ('Sig: 7126', '10.3.5.2', 6),
    ('Sig: 7126', '10.3.5.4', 5),
    ('Sig: 0559', '10.3.5.34', 1),
    ('Sig: 7126', '10.3.5.34', 2),
    ('Sig: 0559', '10.3.5.42', 1),
    ('Sig: 7126', '10.3.5.42', 1),
    ('Sig: 7126', '10.3.5.43', 2)
    ]


    Is there any simple python code to achieve it ?

    Continue reading...

Compartilhe esta Página