permuting several lists (was Re: [Python-Dev] zip() and list-comprehension with commas)

Ken Manheimer klm@digicool.com
Thu, 13 Jul 2000 02:25:30 -0400 (EDT)


On Wed, 12 Jul 2000, Ken Manheimer wrote:

> Guido:
> 
> > I looked in a thesaurus and found a few potential alternatives:
> > [...]
> > interlace
> > [...]
> > If none of these appeal, I say let's use zip and end this impossibly
> > long thread.
> 
> I actually like interlace a lot.

Huh - how about "lace"?  I like that even more than "interlace" -
shorter, and with a particular, visceral appeal when thinking about
laces that tie clothing together, like shoelaces.  Lacing shoes means
interleaving the laces, and unlacing them means un-interleaving them.
Extraordinarily close visceral/physical analogue for the interlacing
of the list/tuple arguments.

For those that didn't see my posting in the thread "Re: zip() and
list-comprehension with commas", i think it's a good idea to be
explicit about the type of the results, rather than inferring them
from the types of the arguments.  Seem like there are so many contexts
where lists and tuples are interchangeable that it's too easy for a
variable to contain one when you expect the other - and the
reorganizing routine would wind up raising unexpected errors, or
unpredictable results, too often.  Better to be explicit.

And dictionaries seem like reasonable targets for lacing.

>>> lace([], (1, 2, 3), [4, 5, 6,])              Lace
[[1,4], [2,5], [3,6]]                             -%- 
                                                  \ / 
>>> lace((), [1,2,3],(4,5,6))                      X  
((1,4), (2,5), (3,6))                             / \ 
                                                  \ / 
>>> lace({}, (1,2,3), "abc")                       X  
{1:'a', 2:'b', 3:'c'}                             (_)

>>> unlace([], [1,4], [2,5], [3,6])              unlace
[[1, 2, 3], [4, 5, 6]]                            \  /      
                                                  |  |
>>> unlace((), [1,4], [2,5], [3,6])               |  |
((1, 2, 3), (4, 5, 6))                            |  |
                                                  |  |
>>> unlace((), {1:'a', 2:'b', 3:'c'})             |  |
((1, 2, 3), ('a', 'b', 'c'))                      |__|

Also, i like having generators as the results of lacing things...

I wonder whether this will have any inherent meaning for non-english
speakers?  Then again, i'm not sure 'tuple' had a lot of meaning for a 
lot of english or non-english speakers - people get used to it, as
long as it's not using a word commonly known to have a *different*
meaning in context (eg, "zip").

Ken