On Tue, Dec 10, 2019 at 07:21:13PM -0600, Tim Peters wrote:
> [Tim]
> >> For me, most of the time, it's to have an obvious, uniform way to
> >> spell "non-destructively pick an object from a container (set, dict,
> >> list, deque, heap, tuple, custom tree class, ...)".  I don't even have
> >> iterators in mind then, except as an implementation detail.
> 
> [Steven]
> > You can't *non-destructively* pick the first (or next, or any) element
> > of an iterator.
> 
> Obviously.  That's why I wrote "container", and then gave 7 concrete
> examples in case that distinction was too subtle ;-)

It wasn't :-) but we're talking about adding a function to **itertools** 
not "container tools", one which will behave subtly different with 
containers and iterators. Your use-case ("first item in a container") is 
not the same as the semantics "next element of an iterator", even if we 
call the second one "first".

[...]
> I'm not at all bothered that for some arguments `first()` mutates
> state and for others it doesn't, no more than I'm bothered that `for x
> in iterable:` may or may not "consume" the iterable.

*shrug*

Okay, but I am. Iterating over an iterable is a very different use-case.


[...]
> While the meaning of `first()` is clear for any iterable argument.

Sorry Tim, I have to disagree. The meaning of `first` is:

    return the first element of a sequence or container (in standard 
    iteration order), OR the *next* element of an iterator

and I don't think that this is even a little bit clear from the name.


-- 
Steven
_______________________________________________
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/SHAABB7PPZCSCQXHQZRWW4FEYVRVSUPE/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to