find first occurrence of item in list python code example
Example 1: python find first occurrence in list
#iterate through list
for item in yourlist:
#if item is equal to a value
if item == 'value':
#store the item in a variable
yourvar = item
#break out of loop
break
Example 2: python get first occurrence in list
next(obj for obj in objs if obj.val==5)