[Python-ideas] iterable.__unpack__ method

Nick Coghlan ncoghlan at gmail.com
Sun Feb 24 06:40:49 CET 2013


On Sun, Feb 24, 2013 at 12:12 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> I definitely like Terry's idea of using ", ..." to say "and ignore the
> rest". Simple, elegant and can be restricted to the last element so it works
> with infinite iterators and large sequences. It also allows incremental
> unpacking of ordinary iterators.

I want to expand on this a bit now I'm back on a real computer, since
it wasn't immediately obvious to me how well the ", ..." proposal
supports incremental unpacking, but it became clear once I thought of
this simple example:

    iterargs = iter(args)
    command, ... = iterargs # Grab the first element, leave the rest
in the iterator
    commands[command](*iterargs) # Pass the rest to the command

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list