How to find the index of the nth time an item appears in a list?
Using list comprehension and enumerate: >>> x = [ ‘w’, ‘e’, ‘s’, ‘s’, ‘s’, ‘z’,’z’, ‘s’] >>> [i for i, n in enumerate(x) if n == ‘s’][0] 2 >>> [i for i, n in enumerate(x) if n == ‘s’][1] 3 >>> [i for i, n in enumerate(x) if n == ‘s’][2] 4 >>> [i for … Read more