Re: Inverse of dict(zip(x,y))

2009-03-06 Thread Tino Wildenhain
Andre Engels wrote: On Thu, Mar 5, 2009 at 6:01 PM, Tino Wildenhain t...@wildenhain.de wrote: Still I'd like to see an application where this really matters (that keys() and values() match in order) I think there are many such applications, but also that in each of those cases it's a

Re: Inverse of dict(zip(x,y))

2009-03-06 Thread Tino Wildenhain
Hi, psykeedelik wrote: On Mar 5, 6:01 pm, Tino Wildenhain t...@wildenhain.de wrote: Piet van Oostrum wrote: Andre Engels andreeng...@gmail.com (AE) wrote: AE On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle icym...@gmail.com wrote: Can someone suggest a easy method to do the inverse of dict(zip

Re: Inverse of dict(zip(x,y))

2009-03-06 Thread Tino Wildenhain
Andre Engels wrote: On Thu, Mar 5, 2009 at 7:46 PM, Andre Engels andreeng...@gmail.com wrote: If the dict = {key1: val1, key2: val2, ...}, you can do: for key in dict: plot(key,dictionary[key]) Of course I meant: for key in dict: plot(key,dict[key]) Which would be the verbose

Re: Inverse of dict(zip(x,y))

2009-03-05 Thread Tino Wildenhain
Piet van Oostrum wrote: Andre Engels andreeng...@gmail.com (AE) wrote: AE On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle icym...@gmail.com wrote: Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make

Re: Inverse of dict(zip(x,y))

2009-03-05 Thread Andre Engels
On Thu, Mar 5, 2009 at 6:01 PM, Tino Wildenhain t...@wildenhain.de wrote: Still I'd like to see an application where this really matters (that keys() and values() match in order) I think there are many such applications, but also that in each of those cases it's a mis-programming of something

Re: Inverse of dict(zip(x,y))

2009-03-05 Thread psykeedelik
On Mar 5, 6:01 pm, Tino Wildenhain t...@wildenhain.de wrote: Piet van Oostrum wrote: Andre Engels andreeng...@gmail.com (AE) wrote: AE On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle icym...@gmail.com wrote: Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two

Re: Inverse of dict(zip(x,y))

2009-03-05 Thread Andre Engels
On Thu, Mar 5, 2009 at 7:07 PM, psykeedelik icym...@gmail.com wrote: I usually get properties that I compute, in a dictionary like property = [key1: val1, key2:val2, ...] and then I usually want to plot them in pylab, which AFAIK requires x and y as lists for the plot argument. Then I need to

Re: Inverse of dict(zip(x,y))

2009-03-05 Thread Andre Engels
On Thu, Mar 5, 2009 at 7:46 PM, Andre Engels andreeng...@gmail.com wrote: If the dict = {key1: val1, key2: val2, ...}, you can do: for key in dict:    plot(key,dictionary[key]) Of course I meant: for key in dict: plot(key,dict[key]) -- André Engels, andreeng...@gmail.com --

Re: Inverse of dict(zip(x,y))

2009-03-05 Thread Carl Banks
On Mar 5, 9:01 am, Tino Wildenhain t...@wildenhain.de wrote: Piet van Oostrum wrote: Andre Engels andreeng...@gmail.com (AE) wrote: AE On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle icym...@gmail.com wrote: Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two

Inverse of dict(zip(x,y))

2009-03-04 Thread lone_eagle
Hi all, This might be trivial ... Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any

RE: Inverse of dict(zip(x,y))

2009-03-04 Thread Andreas Tawn
Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x = [x1, x2

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Paul Rubin
lone_eagle icym...@gmail.com writes: So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...] and y = [y1, y2, ...] This may be a bit of a mind bender,

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Andre Engels
On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle icym...@gmail.com wrote: Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread psykeedelik
On Mar 4, 11:06 am, Paul Rubin http://phr...@nospam.invalid wrote: lone_eagle icym...@gmail.com writes: So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x =

RE: Inverse of dict(zip(x,y))

2009-03-04 Thread Peter Otten
Andreas Tawn wrote: Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Tino Wildenhain
lone_eagle wrote: Hi all, This might be trivial ... Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Hrvoje Niksic
psykeedelik icym...@gmail.com writes: Keys and values are listed in an arbitrary order which is non- random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions. I hope it does not mean that the key-value mapping is not guaranteed,

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Lie Ryan
Andre Engels wrote: y = d.values() might also work, but I am not sure whether d.keys() and d.values() are guaranteed to use the same order. If they were called immediately after each other I think they should, but better not rely on it. -- http://mail.python.org/mailman/listinfo/python-list

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Tino Wildenhain
Lie Ryan wrote: Andre Engels wrote: y = d.values() might also work, but I am not sure whether d.keys() and d.values() are guaranteed to use the same order. If they were called immediately after each other I think they should, but better not rely on it. otoh, I could not think of any use

RE: Inverse of dict(zip(x,y))

2009-03-04 Thread Andreas Tawn
So, if x and y are two lists, it is easier to make a dictionary using d = dict(zip(x,y)), but if I have d of the form, d = {x1:y1, x2:y2, ...}, what is there any trick to get lists x = [x1, x2, ...] and y = [y1, y2, ...] Cheers, Chaitanya. x = d.keys() y = d.values() But be aware that you

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Piet van Oostrum
Andre Engels andreeng...@gmail.com (AE) wrote: AE On Wed, Mar 4, 2009 at 11:02 AM, lone_eagle icym...@gmail.com wrote: Can someone suggest a easy method to do the inverse of dict(zip(x,y)) to get two lists x and y? So, if x and y are two lists, it is easier to make a dictionary using d

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Lorenzo
Having a look at python documentation I found: zip() in conjunction with the * operator can be used to unzip a list: x = [1, 2, 3] y = [4, 5, 6] zipped = zip(x, y) zipped [(1, 4), (2, 5), (3, 6)] x2, y2 = zip(*zipped) x == x2, y == y2 True So, x2, y2 = zip(*d.items()) should fix your

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Lie Ryan
Lorenzo wrote: zip() in conjunction with the * operator can be used to unzip a list: That's because zip is the inverse operation of zip. I remember someone saying that zip's typical name is transpose (like in matrix transpose). a == zip(*zip(*a)) nitpick * in argument unpacking is not

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Paul McGuire
On Mar 4, 5:33 am, Lie Ryan lie.1...@gmail.com wrote: Andre Engels wrote: y = d.values() might also work, but I am not sure whether d.keys() and d.values() are guaranteed to use the same order. If they were called immediately after each other I think they should, but better not rely on it.

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Paul McGuire
On Mar 4, 5:33 am, Lie Ryan lie.1...@gmail.com wrote: Andre Engels wrote: y = d.values() might also work, but I am not sure whether d.keys() and d.values() are guaranteed to use the same order. If they were called immediately after each other I think they should, but better not rely on it.

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Benjamin Peterson
Andre Engels andreengels at gmail.com writes: y = d.values() might also work, but I am not sure whether d.keys() and d.values() are guaranteed to use the same order. They are for the builtin dictionary type, but that requirement does not extend to any other mapping type. (It's not a requirement

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Steven D'Aprano
On Wed, 04 Mar 2009 08:00:14 -0800, Paul McGuire wrote: On Mar 4, 5:33 am, Lie Ryan lie.1...@gmail.com wrote: Andre Engels wrote: y = d.values() might also work, but I am not sure whether d.keys() and d.values() are guaranteed to use the same order. If they were called immediately after

Re: Inverse of dict(zip(x,y))

2009-03-04 Thread Paul Rubin
Steven D'Aprano ste...@remove.this.cybersource.com.au writes: Sure, but if you want two lists, as the OP asked for, then you have to iterate over it twice either way: # method 1: keys = dict.keys() values = dict.values() # method 2: keys, values = zip(*dict.items()) First you