On 16.03.2016 17:37, Random832 wrote:
On Wed, Mar 16, 2016, at 11:17, Sven R. Kunze wrote:
I can imagine that. Could you describe the general use-case? From what I
know, "else" is executed when you don't "break" the loop. When is this
useful?

for item in collection:
    if good(item):
       thing = item
       break
else:
    thing = default # or raise an exception, etc

I was thinking about why we don't use it that often. My response to this example:

thing = item if item in collection else default
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to