[Python-ideas] Control Flow - Never Executed Loop Body
Robert Collins
robertc at robertcollins.net
Sun Mar 20 19:27:36 EDT 2016
On 21 March 2016 at 12:23, Vito De Tullio <vito.detullio at gmail.com> wrote:
> Andrew Barnert via Python-ideas wrote:
>
>> More generally, I think if this feature were to be added, "empty" is a
>> reasonable name. The idiomatic way to write it today is something like:
>>
>> elem = empty = object()
>> for elem in seq:
>> do_stuff(elem)
>> if elem is empty:
>> do_empty_seq_stuff()
>>
>> So you're basically looking for syntactic sugar that abbreviated "if ...
>> is empty:", right?
>
> Maybe I'm missing something, but shoulnd't be like
>
> if seq:
> for elem in seq:
> do_stuff(elem)
> else:
> do_empty_seq_stuff()
>
> a trivial code handling an empty list?
seq = iter([])
will cause your example to not run do_empty_seq_stuff().
-Rob
--
Robert Collins <rbtcollins at hpe.com>
Distinguished Technologist
HP Converged Cloud
More information about the Python-ideas
mailing list