[Python-ideas] Generator unpacking
Erik
python at lucidity.plus.com
Fri Feb 12 19:22:58 EST 2016
On 13/02/16 00:03, Andrew Barnert wrote:
> On Feb 12, 2016, at 15:35, Michael Selik <mike at selik.org
> <mailto:mike at selik.org>> wrote:
> Creating a range just to zip with just to throw away the values seems
> like overcomplicating things. Unless there's some performance benefit to
> doing it that way, why not just keep it simple?
I agree. I've never used islice() before, so I missed that as a better
way of yielding the first 'n' values.
> That's exactly what was in my email, as the way to do things today,
> which he was replying to:
>
>> Or you can use itertools.islice to make it more compact:
>> >
>> > >>> a, b = itertools.islice(c, 2)
>> > >>> rest = c
>
> So I think we can assume that he thinks his version improves over that,
> or he wouldn't have suggested it...
My "suggestion" was simply that perhaps creating a very short wrapper
function somewhere that handles whether the sequence is already an
iterator or not etc (and using islice() or whatever - I don't really
care ;)) would perhaps be a more pragmatic option than trying to squeeze
in some syntax change or underlying unpack heuristic/mechanic (which is
where I thought the thread was heading).
Perhaps I didn't express that very clearly. I'm happy do drop it ;)
E.
More information about the Python-ideas
mailing list