Look for match in a nested list in Python
- by elfuego1
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]]