Python for and if on one line
You are producing a filtered list by using a list comprehension.i is still being bound to each and every element of that list, and the last element is still ''three'', even if it was subsequently filtered out from the list being produced.. You should not use a list comprehension to pick out one element. Just use a for loop, and break to end it:. for elem in my_list: if elem == …