On Wed, Dec 11, 2019 at 9:48 PM Tim Peters <tim.pet...@gmail.com> wrote:
> [Tim] > >> Every suggestion here so far has satisfied that, if S is a non-empty > set, > >> > >> assert next(iter(S)) is first(S) > >> > >> succeeds. That is, `first()` is _defined_ by reference to iteration > >> order. It's "the first" in that order (hence the name). > > [Stephen J. Turnbull <turnbull.stephen...@u.tsukuba.ac.jp>] > > The problem I'm concerned with is that sometimes users' definitions of > > words differ from a computer language's definitions of words. That's > > why I used the word "natural", which doesn't really have much to do > > with the way a computer language defines things, but frequently > > features in human thought. > > > > Whether that potential difference matters here is an empirical > > question. > > > > Theoretically, I can say "Explicit is better than implicit." > > I.e., the call to 'iter' tells us exactly what order is being used. > > But hasn't it already been settled by experience? There is nothing > unique about `first(set)` implicitly appealing to iteration order. A > set passed as the iterable to _any_ itertools function does exactly > the same: > > >>> import itertools > >>> list(itertools.zip_longest(set("abcde"), range(5))) # can vary from > run to run > [('a', 0), ('e', 1), ('c', 2), ('d', 3), ('b', 4)] > >>> list(itertools.compress(set("abcde"), [1]*5)) # but is consistent > within a run > ['a', 'e', 'c', 'd', 'b'] > >>> list(itertools.takewhile(lambda x: True, set("abcde"))) > ['a', 'e', 'c', 'd', 'b'] > > So do, e.g., some builtins: > > >>> list(map(ord, set("abcde"))) > [97, 101, 99, 100, 98] > >>> [ord(ch) for ch in set("abcde")] > [97, 101, 99, 100, 98] > > > > That's *my* opinion in this case, and I don't hold *you* to it just > > because I'm quoting you. (I am amused, though.) > > I just don't see the potential for "new" bafflement if itertools.first > works exactly the same way as itertools.anything_else _has_ worked, in > this respect, all along. Give users some credit. Programming is > baffling, period, at first. But to those who persist, nothing becomes > truly unbearable ;-) > I'm also sure the docs will say "Returns the first item yielded by the iterable." That last word is a dead give-away on how the choice will be made on any collection, Sequence or not. 😉 (Doubly true if this goes into itertools.) There's also the contingency of users who will think of the question "how would this function think of what "first" is for non-order collections?" will simply think "iterator" and be done with thinking. IOW I understand the desire to have a function that is fully self-explanatory, but I view take() as more ambiguous as it doesn't say where you will take form (e.g. are you going to treat a list as a deque or a stack?), but first() has a clear understanding the instant you think about this operating on iterables (which is as universal of a data structure concept across collection types as we have).
_______________________________________________ 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/O6OD3XNYEECJJXEZJK3RV35NGWXC6MFF/ Code of Conduct: http://python.org/psf/codeofconduct/