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

Paul Prescod
Thu, 13 Jul 2000 01:12:57 -0500

Ken Manheimer wrote:
> ...
> 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.  

Well, we (at least you and I) agree that we should use a generator, so
you don't really have any control over the outer data structure without
using a cast. I think it is safe to default the inner data structure to
tuple. Tuples are safe because errors involving them cause TypeErrors
whereas accidental writes to shared lists cause weird mutation bugs.

Here are some variants you can get using recently proposed features:

List of tuples:

>>> list( lace( a, b, c ))

A tuple of tuples:

>>> tuple( lace( a, b, c))

A tuple of lists:

>>> tuple( [for x in lace( a, b, c)]: list(x) )

A list of lists:

>>> list( [for x in lace( a, b, c)]: list(x) )

A dictionary:

>>> dict( lace( a, b, c ))

 Paul Prescod - Not encumbered by corporate consensus
Simplicity does not precede complexity, but follows it.