[Tutor] for loop

Ron A clickron at webtv.net
Wed Jan 7 18:41:15 EST 2004


I'm experimenting and would like 'yes' to be printed only if 5 is not in
the list, but I want to look in each list. This prints out two yeses.
How do I get it to print just one 'yes'?

x = [[1,2,3],[2,4,6],[8,4,5,6],[9,8,7]]

for num in x:
    if 5 in num:
        break
    else:
        print 'yes'    




More information about the Tutor mailing list