473,320 Members | 1,848 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.

zip() or what?

Hi all

Many thanks to those that answered my questions about whitespace and ord()
being reverse of chr(). As well as the 2 things I asked about I learned
about 5 other useful things.

This I am trying to flip an array around so that the "subscripts" happen
in the opposite order and reading the docs I thought that zip() did this.
So I tried it like this:

x=[[0.1,0.2],[1.1,1.2],[2.1,2.2]]
print zip(x)

and what I got was (removing the .0000000001s):

[([0.1, 0.2],), ([1.1, 1.2],), ([2.1, 2.2],)]

which is just my original array with an extra useless level in it.
What I really wanted was this:

[[0.1,1.1,2.1],[0.2,1.2,2.2]]

So my question is how do I do that easily?
And what on earth is zip() doing?

Alternatively, is there a construct to get x[*][i] if you know what I mean?

Have fun

Ray

Jul 18 '05 #1
4 2175
Ray Tomes wrote:
What I really wanted was this:

[[0.1,1.1,2.1],[0.2,1.2,2.2]]

So my question is how do I do that easily?
You wanted

zip(*x)
Alternatively, is there a construct to get x[*][i] if you know what I
mean?


Probably

[i[1] for i in x]

or

map(lambda i: i[1], x)

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ What would physics look like without gravitation?
\__/ Albert Einstein
Jul 18 '05 #2
Erik Max Francis wrote:
Ray Tomes wrote:
request to flip array ...
zip(*x) Alternatively, is there a construct to get x[*][i] if you know what I
mean?

[i[1] for i in x]
Thanks Erik, these do just what I want.
I can understand the 2nd one, but I don't get the meaning of the * in the
first. Is this like the opposite of putting [] around something or what?
Under what circumstances can an * be used like this, and what is it
called? - I don't know how to look for it in the docs :-)

also, ...

ac*****@easystreet.com wrote: Ray Tomes wrote:
This I am trying to flip an array around so that the "subscripts" happen
in the opposite order
[x[-i-1] for i in range(len(x))]


Thanks Al, but that was not the flip I was looking for sorry - I hadn't
realised it could be taken another way. I wanted to swap the subscripts
with each other (a 45 degree reflection) not within one subscript end to
end (a 90 degree reflection). Erik has done the one I wanted.

Jul 18 '05 #3
Erik Max Francis wrote:
Ray Tomes wrote:
request to flip array ...
zip(*x) Alternatively, is there a construct to get x[*][i] if you know what I
mean?

[i[1] for i in x]
Thanks Erik, these do just what I want.
I can understand the 2nd one, but I don't get the meaning of the * in the
first. Is this like the opposite of putting [] around something or what?
Under what circumstances can an * be used like this, and what is it
called? - I don't know how to look for it in the docs :-)

also, ...

ac*****@easystreet.com wrote: Ray Tomes wrote:
This I am trying to flip an array around so that the "subscripts" happen
in the opposite order
[x[-i-1] for i in range(len(x))]


Thanks Al, but that was not the flip I was looking for sorry - I hadn't
realised it could be taken another way. I wanted to swap the subscripts
with each other (a 45 degree reflection) not within one subscript end to
end (a 90 degree reflection). Erik has done the one I wanted.

Jul 18 '05 #4
Ray Tomes wrote:
I can understand the 2nd one, but I don't get the meaning of the * in
the
first. Is this like the opposite of putting [] around something or
what?
Under what circumstances can an * be used like this, and what is it
called? - I don't know how to look for it in the docs :-)


f(x) calls the function f with the single argument x. f(*x) calls f
with the arguments x, which is expected to be a sequence. The * syntax
comes from defining functions, where a formal argument preceded by *
means, "All the rest of the arguments as a tuple." So:
def f(*x): print x .... s = [1, 2, 3]
f(s) ([1, 2, 3],) f(*s)

(1, 2, 3)

The old way of writing the function call f(*x) was apply(f, x).

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ War is like love, it always finds a way.
\__/ Bertolt Brecht
Jul 18 '05 #5

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

Similar topics

2
by: Frostillicus | last post by:
I'm trying to get an ASP to return a zip file to the remote browser from an Image (BLOB) field in SQL Server 2000 but Internet Explorer keeps saying: Cannot open C:\Documents and...
11
by: News | last post by:
I have a database of zipcodes with latitude and longitude. I also have the method of calculating the distance between two zipcodes. What I want to know is if there is an efficient algorithm for...
6
by: David Lozzi | last post by:
Hey All, I need to add a locator service for asp.net where a user would specify a zip code and then the returned list would be displayed in order of closest to furthest. I realize this is a third...
38
by: Steven Bethard | last post by:
> >>> aList = > >>> it = iter(aList) > >>> zip(it, it) > > That behavior is currently an accident. >http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=1121416
1
by: Arkady Renko | last post by:
Gday Guys I'm attempting to create zip files on the fly for some highly compressible, yet very large files stored on my Web server. At present I'm using a class from the Zend library by Eric...
11
by: comp.lang.php | last post by:
Once again, I thought my class method deleteZip() would do the trick, but it never deletes any .zip* file found in a directory: /** * Delete any latent ZIP files found in this album. This...
5
by: techusky | last post by:
I made a script that successfully creates a .zip file of all the files in a directory on my web server, but now what I haven't figured out how to do is how to have it automatically deleted when the...
8
by: =?Utf-8?B?Q2hyaXMgRmluaw==?= | last post by:
I am trying to make a minor modification to the code below and need some assistance. Currently this code is using the java.util, java.util.zip, and java.io assemblies from the vjslib.dll assembly....
1
by: sandhyabhavani | last post by:
This article is used to zip a file or directory using vb.net. The classes and method to zip a file is availale in java.io, java.util, java.util.zip class library.To import these you have to add a...
7
by: moogyd | last post by:
Hi group, I have a basic question on the zip built in function. I am writing a simple text file comparison script, that compares line by line and character by character. The output is the...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.