
On Mon, Dec 9, 2019 at 6:19 PM Juancarlo Añez <apalala@gmail.com> wrote:
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.
Python historian here. dict.get() does *not* require you to specify a default -- in fact its *sole* purpose in life is to not raise an exception. And it has the sensible default default of None. There is already a spelling that does raise: dict[key]. Similarly, there is already a spelling of first() (or close enough) that raises: 1-arg next(). If 1-arg first() would also raise, it would fail the rule "similar things should be spelled similarly, and different things should be spelled differently". I am not making this rule up -- it's an old design principle that Lambert Meertens used for ABC, Python's predecessor. It just didn't make it in the Zen of Python, unless you want to interpret "there should be one [...] way to do it" as its spiritual descendant. IMO "one raises StopIteration and one raises ValueError" is not enough to warrant two different ones, nor is "one calls iter() and the other doesn't." But "one raises and the other doesn't" is a significant enough difference (as the example of dict.get() shows). FWIW I think "first()" is a fine name to get one element from a set -- it's not like the iteration order is a secret, and it's not called "lowest". The other schemes to get one item out of a set in O(1) time will return the same element, since the only sensible way to do it is to iterate and stop after one iteration. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>