Idiom for default values when unpacking a tuple

Mark Wooding mdw at nsict.org
Wed Nov 24 10:54:27 EST 2004


Paul McGuire <ptmcg at austin.rr._bogus_.com> wrote:

> Is there a clean Python idiom for unpacking a tuple so that any
> unassigned target values get a default, or None

If i is a tuple you want unpacked, then something like

  (lambda a, b, c, d = None: (a, b, c, d))(*i) 

is the expanded version with defaults substituted.

-- [mdw]



More information about the Python-list mailing list