Having both if() and for() statements in one liner
Dave Angel
davea at davea.name
Tue Sep 17 14:54:51 EDT 2013
On 17/9/2013 09:21, Ferrous Cranus wrote:
> I just want to say tot he program that
>
> that only run the for statement if and only if person=='George'
>
> I dont see nay reason as to why this fails
>
> perhaps like:
>
> for times in range(0, 5) if person=='George':
>
> but that fails too...
> there must be written on soem way.
>
>
untested:
for times in range(0, 5 if person=="George" else 0):
But i also greately prefer the canonical version.
--
DaveA
More information about the Python-list
mailing list