Idiom for default values when unpacking a tuple

Mark Wooding mdw at nsict.org
Wed Nov 24 16:54:27 CET 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