[Python-ideas] Integrate some itertools into the Python syntax
Nikolaus Rath
Nikolaus at rath.org
Thu Mar 24 18:45:15 EDT 2016
On Mar 24 2016, Chris Barker <chris.barker-32lpuo7BZBA at public.gmane.org> wrote:
> And it came up in another recent thred about a mechanism for doing
> something after a for loop that didn't loop -- in that case, for sequences,
> the idiom is obvious:
>
> if seq:
> do_the_for_loop
> else:
> do_somethign else since the loop wont have run.
>
> But when you plug in an arbitrary iterable into that, it doesn't work, and
> there is no easy, obvious, and robust idiom to replace that with.
Hmm.
empty = True
for stuff in seq:
empty = False
do_stuff
if empty:
do_something_else
is two lines longer than the above (if you expand the do_the_for_loop)
and seems pretty obvious and robust. What do you dislike about it?
Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«
More information about the Python-ideas
mailing list