0

I want to check if zero is in this list of lists. For example:

lst = [[2,2,2],[2,2,0],[2,2,2],[2,2,2]]

If lists in 'lst' contains "0", then print("Yes"), else print("No"). The above list should give the result of "Yes", since lst[1][2] == 0.

Here is my code, but it doesn't work:

if (0 in (lst[x] for x in range(len(lst)))):
    print("Yes")
else:
    print("No")
eyllanesc
  • 235,170
  • 19
  • 170
  • 241

1 Answers1

0

Instead of using range(len), you can directly iterate over sublists:

for sublist in lst:
    if 0 in sublist:
        print("Yes")
    else:
        print("No")

With given input, output:

No
Yes
No
No
brokenfoot
  • 11,083
  • 10
  • 59
  • 80