Juancarlo Añez writes:

 > the_first_item_if_ordered = next(iter(container), default='not found')

Ouch!

 > one_item_if_any = first(return_a_set(), default=-1)

Is "first" really the right color for this bikeshed?  Maybe it's OK,
but speaking precisely you can't ask for "first" of a set.  The
question is "will 'any one' do?"  There may be a natural (pre)order on
the objects of a set, so that

    first_item_if_any = first(sorted(return_a_set(), default=-1))

is the desired result.  I'm not sure if this is occurs more than very
rarely in practice (but I know variations in iteration order for sets
across invocations has bitten me in testing).  It would be nasty to
debug.

Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GZOJO3DVIC6E2NBNAZSWR4TIW7TN23HI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to