[Python] Array Group Mapping

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a python code. I have a list of arrays with various IDs in them. Now i want to group all common IDs and assign a singular name to them Problem is that if any one of the ID in a array is also present in a different array, I want to consider all IDs of both arrays as part of the same group.

    For Example, consider 5 arrays as follows :

    [Q,W,E,R]
    [A,S,D,F]
    [Z,X,C,V]
    [P,O,I,R]
    [L,J,A,Z]


    Now their grouping should be as follows :

    [Q,W,E,R] - Group 1
    [A,S,D,F] - Group 2
    [Z,X,C,V] - Group 2 (Because of connecting array element in row 5)
    [P,O,I,R] - Group 1
    [L,J,A,Z] - Group 2 (Connecting element in row 2)


    Final Output :

    Q, Group 1
    W, Group 1
    E, Group 1
    R, Group 1
    A, Group 2
    S, Group 2
    D, Group 2
    F, Group 2
    Z, Group 2
    X, Group 2
    C, Group 2
    V, Group 2
    P, Group 1
    O, Group 1
    I, Group 1
    L, Group 2
    J, Group 2


    I am confused as to which graph structure to use to solve this.

    Continue reading...

Compartilhe esta Página