What would be the most efficient\elegant way in Python to find the index of the first non-empty item in a list?
For example, with
list_ = [None,[],None,[1,2],'StackOverflow',[]]
the correct non-empty index should be:
3
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if you don’t want to raise a
StopIterationerror, just provide default value to thenextfunction:P.S. don’t use
listas a variable name, it shadows built-in.