question about for cycle

tokland at gmail.com tokland at gmail.com
Sat Sep 29 15:38:43 CEST 2007


On 29 sep, 12:04, "fdu.xia... at gmail.com" <fdu.xia... at gmail.com> wrote:

> for i in generator_a:  # the first "for" cycle
>      for j in generator_b:
>          if something_happen:
>              # do something here ..., I want the outer cycle to break
>              break

Do you like this?

generator_ab = ((x, y) for x in generator_a for y in generator_b)
for i, j in generator_ab:
    if condition:
        # do something
        break




More information about the Python-list mailing list