Re: question about for cycle
- From: "fdu.xiaojf@xxxxxxxxx" <fdu.xiaojf@xxxxxxxxx>
- Date: Sat, 29 Sep 2007 22:34:21 +0800
tokland@xxxxxxxxx wrote:
> On 29 sep, 12:04, "fdu.xia...@xxxxxxxxx" <fdu.xia...@xxxxxxxxx> 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
>
In this case, the tuple generator_ab must be generated first. Sometime
it maybe a waste to generate all possible combinations of i,j first.
I have googled and found the PEP-3136(Labeled break and continue),
which has been rejected. I have also read why Guido rejected this PEP(
http://mail.python.org/pipermail/python-3000/2007-July/008663.html),
but I still think labeled break and continue is a good feature in my
case.
Regards,
.
- Follow-Ups:
- Re: question about for cycle
- From: George Sakkis
- Re: question about for cycle
- References:
- question about for cycle
- From: fdu.xiaojf@xxxxxxxxx
- Re: question about for cycle
- From: tokland
- question about for cycle
- Prev by Date: Re: sorteddict [was a PEP proposal, but isn't anymore!]
- Next by Date: Re: Python 3.0 migration plans?
- Previous by thread: Re: question about for cycle
- Next by thread: Re: question about for cycle
- Index(es):