473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

inverse of the zip function

Is there a function which takes a list of tuples and returns a list of
lists made up of the first element of each tuple, the second element of
each tuple, etc.?

In other words, the the inverse of the built-in zip function?

David

Jul 18 '05 #1
6 7335
Terry Reedy wrote:
"David C. Fox" <da*******@post.harvard.edu> wrote in message
news:9sBVa.12998$o%2.6289@sccrnsc02...
Is there a function which takes a list of tuples and returns a list


of
lists made up of the first element of each tuple, the second element


of
each tuple, etc.?

In other words, the the inverse of the built-in zip function?

Go to
http://groups.google.com/groups?hl=e...mp.lang.python
enter 'zip inverse', and check search Python only.

TJR


Thanks. I've gotten so used to reading this group with Mozilla Mail
that I forgot about google groups.

David

Jul 18 '05 #2
On Tue, 29 Jul 2003 22:06:20 +0000, Raymond Hettinger wrote:
"David C. Fox" <da*******@post.harvard.edu> wrote in message
news:9sBVa.12998$o%2.6289@sccrnsc02...
Is there a function which takes a list of tuples and returns a list of
lists made up of the first element of each tuple, the second element of
each tuple, etc.?

In other words, the the inverse of the built-in zip function?


When used with the * operator, zip() is its own inverse:


This (obviously) doesn't work when z has length 0 or 2.
I don't quite understand why zip is overloaded ...

Oh, hang on, it does work for length 2! that's neat-o,
and perhaps that's why zip was extended. Is it a functional programming
convention, i wonder.

Simon.

Jul 18 '05 #3
On Wed, 30 Jul 2003 08:31:47 +1000, Simon Burton wrote:
On Tue, 29 Jul 2003 22:06:20 +0000, Raymond Hettinger wrote:
"David C. Fox" <da*******@post.harvard.edu> wrote in message
news:9sBVa.12998$o%2.6289@sccrnsc02...
Is there a function which takes a list of tuples and returns a list of
lists made up of the first element of each tuple, the second element of
each tuple, etc.?

In other words, the the inverse of the built-in zip function?


When used with the * operator, zip() is its own inverse:


OK, i think i see now. it's swapping rows<->columns, and might help this
other guy with his gridcontrols. But zip() should return (). No?

Simon.

Jul 18 '05 #4
> >> In other words, the the inverse of the built-in zip function?

When used with the * operator, zip() is its own inverse:


This (obviously) doesn't work when z has length 0 or 2.
I don't quite understand why zip is overloaded ...

Oh, hang on, it does work for length 2! that's neat-o,
and perhaps that's why zip was extended. Is it a functional programming
convention, i wonder.

Simon.

There is no special extension to zip().
It just happens to be one of those functions
like int.__neg__() that is closely related to
its own inverse.

* or apply() serve only to break a list into
individual arguments. So, transpose() can
be defined like this:

def transpose(mat):
return zip(*mat)

The transpose() is its own inverse for rectangular
matrices represented as lists of tuples.
Raymond Hettinger

Jul 18 '05 #5
Raymond Hettinger wrote:
>> In other words, the the inverse of the built-in zip function?
>
> When used with the * operator, zip() is its own inverse: There is no special extension to zip().
It just happens to be one of those functions
like int.__neg__() that is closely related to
its own inverse.

* or apply() serve only to break a list into
individual arguments. So, transpose() can
be defined like this:


I understand why it works as inverse when *<list> creates a argument list of
list element. But don't understand why * works that way in this context.
Does ** do this for maps and keywordargs, too? Hey, this is python - lets
try:
def foo(a=None, b=None): .... pass
.... foo(a=10, b=20)
foo(**{'a':10, 'b':20})


Coooool. Where is that documented? Never stumbled across it so far!

Diez
Jul 18 '05 #6
> I understand why it works as inverse when *<list> creates a argument list of
list element. But don't understand why * works that way in this context.
Does ** do this for maps and keywordargs, too? Hey, this is python - lets
try:
def foo(a=None, b=None): ... pass
... foo(a=10, b=20)
foo(**{'a':10, 'b':20})


Coooool. Where is that documented? Never stumbled across it so far!


http://www.python.org/dev/doc/devel/ref/calls.html
Raymond Hettinger
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Steven Bethard | last post by:
So I know that zip(*) is the inverse of zip(), e.g.: >>> zip(*zip(range(10), range(10))) What's the inverse of izip? Of course, I could use zip(*) or izip(*), e.g.: >>>...
15
by: Jordan Rastrick | last post by:
First, a disclaimer. I am a second year Maths and Computer Science undergraduate, and this is my first time ever on Usenet (I guess I'm part of the http generation). On top of that, I have been...
6
by: vishnu mahendra | last post by:
hello to all, can any one please give me an algorithm to find inverse of a matrix of order n rows and m columns. thank you in advance, vishnu.
9
by: Water Cooler v2 | last post by:
What is the inverse of the sine function? I've been pulling my hair and I have no clue nor memory of how to go about solving this little expression: sine-1 (read sine inverse) of (1-(x/y)) An...
6
by: Randy | last post by:
Hello, Can someone tell me how to derive the Inverse of Math.Log10(value)? Thanks
5
by: Mario | last post by:
How do I get the inverse of a cosine, that is, cos(a) = x, I have x and I need to know a? I don't need the hyperbolic inverse, unless I can use it to get the cosine inverse. Greetings, Mario
2
by: bartsimpson8882002 | last post by:
I was wondering if scipy/numpy has the inverse cumulative normal function, ie the function f in this expression f(scipy.stats.norm.cdf(1.2)) = 1.2 or more generally, a function f which fits...
4
by: Jonathan Fine | last post by:
Hello As part of the MathTran project I found myself wanting to maintain a bijection between long names and short names. http://www.open.ac.uk/mathtran In other words, I wanted to have two...
10
by: Paul McGuire | last post by:
Is there an inverse function to the builtin 'id'? The poster who asked about 1-to-1, 1-to-n, etc. relationships (presumably in CS terms - I hope I didn't misread some porn spam by mistake), got me...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.