[Steven D'Aprano <[email protected]>]
> 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".
All itertools functions accept arbitrary iterables, which includes all
iterators of all kinds, and includes everything else `iter()` can be
applied to (such as most containers).
`first()` would be exactly the same as all other itertools functions
in this respect.
Yes, you _can_ make mistakes because of it. That gets a yawn from me.
It's nothing new, and comes with the territory of Python being a
multi-paradigm language.
...
>> 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
As I said, the meaning _is_ clear to you.
> and I don't think that this is even a little bit clear from the name.
I didn't claim it was clear from the name alone. As always, what I
care about is whether the name is sufficient to remind users of the
meaning _after_ they've learned what it means. For a non-empty
iterable `it`,
a = first(it)
is the same as:
for a in it:
break
Once that's grasped, it's essentially impossible to forget what
`first()` means (it's simply the first value returned from iterating
over `it`).
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/VHDYIDZ6EELSETVNXZKYISFHKVNU2K36/
Code of Conduct: http://python.org/psf/codeofconduct/