472,374 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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 7226
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.