> > So while 1-arg next() and the try/except StopIteration pattern are > essential and well-known, 2-arg next() is relatively esoteric and > consequently (I think) not nearly as well-known. >
And knowing that you must use *iter()* for 2-arg *next()* to (maybe) work right is idiosyncratic. It takes a "Python historian" to understand why it *may be correct* to use: the_first_item_if_ordered = next(iter(container), default='not found') While the semantics of *first()* (whichever the chosen implementation) are straightforward to explain: one_item_if_any = first(return_a_set(), default=-1) or: the_first_item = first(sorted(container)) I agree with others in that the "*default*" argument should be explicit instead of implied. It's how *dict.get()*, and *dict.pop()*, etc., work. The exceptions raised when nothing can be returned from *first()* and there is no *default=* should be the same. -- Juancarlo *Añez*
_______________________________________________ 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/TEFCNAFT2AOXVHQYUB6O6MVXGCQBTGAU/ Code of Conduct: http://python.org/psf/codeofconduct/