[Python-ideas] while conditional in list comprehension ??

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Tue Jan 29 15:32:39 CET 2013


> Boris Borcic <bborcic at ...> writes:
>
> 
> |>>> def notyet(cond) :
> 	if cond :
> 		raise StopIteration
> 	return True
> 
> |>>> list(x for x in range(100) if notyet(x>10))
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> 

Are you trying to say you entered that code and it ran?
I would be very surprised: if you could simply 'raise StopIteration' within the
'if' clause then there would be no point to the discussion.
But as it is, your StopIteration should not be caught by the 'for', but will be
raised directly. Did you try running it?






More information about the Python-ideas mailing list