On Dec 9, 2019, at 22:07, Wes Turner <wes.tur...@gmail.com> wrote:
> 
> 
> Sets are not collections.abc.Sequence because they do not implement 
> __getitem__.
> Are there other unordered Iterables in the standard library

Again, it depends on what you’re trying to distinguish by that word 
“unordered”. Mappings (including dict) and their views, Sets (including 
frozenset), Iterators (including file objects, map, filter, generators, and 
most itertools functions), and many other things are Iterables without being 
Sequences. I have no idea which if any of these you mean by “unordered”. For 
every single one of them, just like for set, first(it) will give you the same 
value as list(it)[0] (albeit a different exception if they’re empty), so I 
don’t see why any of them are confusing. What else would you expect first to 
do? And, without knowing why you think first should mention any of them, I have 
no idea which ones it should mention.

>> On Tue, Dec 10, 2019 at 12:44 AM Tim Peters <tim.pet...@gmail.com> wrote:
>> 
>> ... as is my _current_ idiom:
>> 
>>    for a in iterable:
>>        break
>>    else:
>>        raise ...
> 
> Is this pattern in the tutorial?

No, but you will find it on StackOverflow. I don’t think it needs to be in the 
tutorial. If needing to raise a specific exception—or just not StopIteration—is 
common enough that novices need to learn it, I think it’s common enough that it 
should be given a name and put in the itertools recipes or module, or at least 
pointed out in more-itertools, rather than teaching people to spell it out 
every time.

>> Plain old
>> 
>>    a = first(iterable)
>> 
>> would be perfect - but only if it raised.
> 
> +1. How is this distinct from:
> 
>    first = next

Because first works with any Iterable; next works only with iterators.
_______________________________________________
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/Q7L5ML4MQRIKTFS2ZYX3N6TB2UL7MFEJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to