>>> lst = [None,[],None,[1,2],'StackOverflow',[]] >>> next(i for i, j in enumerate(lst) if j) 3
if you do not want to raise a StopIteration error, just specify the default value for the next function:
>>> next((i for i, j in enumerate(lst) if j == 2), 42) 42
PS do not use list as a variable name, it is a shadow inline.
Silentghost
source share