breaking out of outer loops

pataphor pataphor at gmail.com
Tue Jan 29 15:55:13 EST 2008


On Tue, 29 Jan 2008 11:51:04 -0800 (PST)
noemailplease0001 at gmail.com wrote:

> Any elegant way of breaking out of the outer for loop than below, I
> seem to have come across something, but it escapes me
> 
> for i in outerLoop:
>    for j in innerLoop:
>        if condition:
>           break
>    else:
>        continue
>     break

Ha! Think outside the box to begin with ...

P.

def cross(args):
    ans = [[]]
    for arg in args:
        ans = [x+[y] for x in ans for y in arg]
    return ans    

def test():
    L = [[0,1,2]]*3
    for a,b,c in cross(L):
        print a,b,c
        
if __name__=='__main__':
        test()



More information about the Python-list mailing list