[(9, '['), (25, ']'), (442, '['), (460, ']'), (558, '['), (576, ']'), (608, ']')]
In this list of tuples I am trying to find key of "]" in the end.
If you take a closer look values goes like this;
[ => ] => [ => ] => [ => ] => [ => ]
But at last step it goes;
] => ]
I want to find key when this unexpected value appear.
How can I do that?
>Solution :
I think you’re looking for something like this:
from itertools import cycle
L = [(9, '['), (25, ']'), (442, '['), (460, ']'), (558, '['), (576, ']'), (608, ']')]
c = cycle(['[', ']'])
for t in L:
if t[1] != next(c):
print(t[0])
break