how to break a for loop?

Petr Jakes mcbooczech at gmail.com
Mon Feb 20 18:15:43 EST 2006


zero_list=[0,0,0,0,0,1,2,3,4]
for x in range(len(zero_list)):
    if zero_list[x]!=0: break
nonzero_list=zero_list[x:]
print nonzero_list

but some more "pythonic" solutions will be posted from other users I
guess :)

HTH
Petr Jakes




More information about the Python-list mailing list