[Python-ideas] for/else statements considered harmful
ubershmekel at gmail.com
Thu Jun 7 13:01:18 CEST 2012
On Thu, Jun 7, 2012 at 1:50 PM, Stephen J. Turnbull <stephen at xemacs.org>wrote:
> def search_in_iterable(key, iter):
> for item in iter:
> if item == key:
> return some_function_of(item)
> return not_found_default
You don't need the "else" there. An equivalent:
def search_in_iterable(key, iter):
for item in iter:
if item == key:
I'm not sure I understood what you meant but I'll assume that by
"plausible"/"reasonable" you meant that it's a good example as to how
for/else is misleading.
Devin Jeanpierre Wrote:
> Also, are you worried about people that read the documentation and
> know what for-else does, or the people that don't or haven't read this
On this issue I'm worried about all sentient programmers.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas