Look for match in a nested list in Python
        Posted  
        
            by elfuego1
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by elfuego1
        
        
        
        Published on 2010-06-13T01:53:05Z
        Indexed on 
            2010/06/13
            12:22 UTC
        
        
        Read the original article
        Hit count: 295
        
Hello everybody,
I have two nested lists of different sizes:
A = [[1, 7, 3, 5], [5, 5, 14, 10]]
B = [[1, 17, 3, 5], [1487, 34, 14, 74], [1487, 34, 3, 87], [141, 25, 14, 10]]
I'd like to gather all nested lists from list B if A[2:4] == B[2:4] and put it into list L:
L = [[1, 17, 3, 5], [141, 25, 14, 10]]
Additionally if the match occurs then I want to change last element of sublist B into first element of sublist A so the final solution would look like this:
L1 = [[1, 17, 3, 1], [141, 25, 14, 5]]
© Stack Overflow or respective owner