Unpaking Tuple
Roy Smith
roy at panix.com
Sat Oct 6 08:46:28 EDT 2012
More information about the Python-list mailing list
Sat Oct 6 08:46:28 EDT 2012
- Previous message (by thread): Unpaking Tuple
- Next message (by thread): Unpaking Tuple
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <mailman.1898.1349519275.27098.python-list at python.org>, Chris Rebert <clp2 at rebertia.com> wrote: > But at any rate: > shortfall = 4 - len(your_tuple) > your_tuple += (None,) * shortfall # assuming None is a suitable default > a, b, c, d = your_tuple > > If you also need to handle the "too many items" case, use slicing: > a, b, c, d = your_tuple[:4] I usually handle both of those cases at the same time: >>> a, b, c, d = (my_tuple + (None,) * 4)[:4]
- Previous message (by thread): Unpaking Tuple
- Next message (by thread): Unpaking Tuple
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list