473,728 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7358
Terry Reedy wrote:
"David C. Fox" <da*******@post .harvard.edu> wrote in message
news:9sBVa.1299 8$o%2.6289@sccr nsc02...
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.1299 8$o%2.6289@sccr nsc02...
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.1299 8$o%2.6289@sccr nsc02...
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
2689
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.: >>> zip(*itertools.izip(range(10), range(10)))
15
2130
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 using Python for a grand total of about a fortnight now. Hence, I apologise if what follows is a stupid suggestion, or if its already been made somewhere else, or if this is not the appropriate place to make it, etc. But I did honestly do some...
6
25204
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
2812
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 answer will be appreciated. Thanks!
6
23922
by: Randy | last post by:
Hello, Can someone tell me how to derive the Inverse of Math.Log10(value)? Thanks
5
6741
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
13646
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 the criteria f(scipy.stats.norm.cdf(x)) = x There is a distribution called invnorm, but I am not sure of how to use
4
2103
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 dictionaries f and g such that f == b
10
4976
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 thinking about containers and ids, and what kind of a container would implement a many-to-many. I happened to still have my Python interpreter open from noodling about another poster's question, using named arguments and parse-time functions...
0
8758
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9422
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9198
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8129
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6716
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3236
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2663
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2161
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.