On 09/06/2022 09:50, Paul Moore wrote:
On Thu, 9 Jun 2022 at 01:12, Steve Jorgensen <ste...@stevej.name> wrote:
My current thinking in response to that is that using islice is a decent 
solution except that it's not obvious. You have to jump outside of the thinking 
about the destructuring capability and consider what else could be used to 
help. Probably, first thing that _would_ come to mind from outside would be 
slicing with square brackets, but that would restrict the solution to only  
work with sequences and not other iterables and iterators as islice does.

That brings up a tangential idea. Why not allow square-bracket indexing of 
generators instead of having to import and utilize islice for that?
Because generators don't have a common (sub-)type, so there's no class
to put the relevant __getitem__ method on.


How so?

>>> def mygen(): yield 42
...
>>> type(mygen())
<class 'generator'>

Best wishes
Rob Cliffe
_______________________________________________
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/A2BS2ZIGSXONEWMQ3QIXFGZJZFF7SWVS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to