Three dumb questions (ordered by dumbness descending)
bbin__ at hotmail.com
Tue Sep 24 09:36:21 EDT 2002
On Tue, 24 Sep 2002 01:45:29 +0000, Steven Feil wrote:
> On Mon, 23 Sep 2002 16:03:21 -0500, Thorsten Kampe wrote:
>> Okay, here they are:
> Ok, I'll take a stab at the first two questions. I do think that a
> little more clarity on your part could make it a bit easer.
> The first thing to remember is that Python is a dynamically typed
> language. It is typed and each object has a type, It would be a little
> easer if you would disclose the type for each object you are referring
>> 1. Why is 'zip(zip(x)) != x' (should be the same because it's the
> Humm, what is is zip(), a function in the standard Python library or is
> it something you or someone else made up? I did a quick search in the
> Python docs and the only zip I found referred to zip compression. If
> this is something from the standard Python libraries please state the
> library it comes from.
> If zip is some general function, then in general, zip(zip(x)) is not
> equal to x. This comes from fundamental abstract algebra. In trig
> sin(sin(x)) is not x. There do exist functions who are there own inverse
> and if zip is one of them then zip(zip(x)) is equal to x.
Zip is a builtin function in Python versions >= 2
This function returns a list of tuples, where the i-th tuple contains the
i-th element from each of the argument sequences. At least one sequence is
required, otherwise a TypeError is raised. The returned list is truncated
in length to the length of the shortest argument sequence. When there are
multiple argument sequences which are all of the same length, zip() is
similar to map() with an initial argument of None. With a single sequence
argument, it returns a list of 1-tuples.
>From the definition you can see that zip is not the transpose of itself.
zip(zip((1,2,3))) = [((1,),), ((2,),), ((3,),)].
If the original sequence is represented by a list like (1,2,3), the result
of a double zip is a doubly nested set of lists or a tree. Thus the result
could also be represented as:
More information about the Python-list