Tuple Semantics - Rationale'?

Thomas Wouters thomas at xs4all.net
Thu Jul 12 07:44:39 EDT 2001


On Wed, Jul 11, 2001 at 10:44:54PM +0000, Quinn Dunkan wrote:

> No, what I mean by that is what python calls "tuple unpacking".  For instance:

> t = ((green, (10, 20), 1),
>      (blue, (20, 30), 0),
>      (green, (40, 20), 1))
> 
> for (color, (x, y), active) in t:
>     ...
> 
> def display((color, (x, y), active)):
>     ...
> 
> map(display, t)

> might be quicker and clearer than throwing together some class for the same.
> Although some might disagree about that 'def' line (and I might be one of them
> <wink>).

Note that that's called "sequence unpacking" nowadays, and it works on all
sequence types. That means, anything that has a '__getitem__' hook (or the C
equivalent) and anything that supports the iteration interface (in the
future Python 2.2) -- which includes classes.

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list