Re: Create dict from two lists

2006-02-10 Thread py
Iain King wrote: > Short answer - you can't. Dictionaries aren't sequential structures, > so they have no sorted form. You can iterate through it in a sorted > manner however, as long as you keep your list of keys: > > keys.sort() > for k in keys: > print d[k] > > Iain duh!thanks. --

Re: Create dict from two lists

2006-02-10 Thread Iain King
py wrote: > Thanks, itertools.izip and just zip work great. However, I should have > mentioned this, is that I need to keep the new dictionary sorted. > > d = {1:'first', -5 : 'negative 5', 6:'six', 99:'ninety-nine', > 3:'three'} > keys = d.keys() > keys.sort() > vals = map(d.get, keys) > > At th

Re: Create dict from two lists

2006-02-10 Thread bearophileHUGS
py: > Thanks, itertools.izip and just zip work great. However, I should have > mentioned this, is that I need to keep the new dictionary sorted. A Python dictionary is an unsorted data structure, so you cannot have it sorted as you please. (I have seen that lot of people ask for a sorted dictiona

Re: Create dict from two lists

2006-02-10 Thread Mikael Olofsson
py wrote: > Thanks, itertools.izip and just zip work great. However, I should have > mentioned this, is that I need to keep the new dictionary sorted. Dictionaries aren't sorted. Period. /MiO -- http://mail.python.org/mailman/listinfo/python-list

Re: Create dict from two lists

2006-02-10 Thread py
Thanks, itertools.izip and just zip work great. However, I should have mentioned this, is that I need to keep the new dictionary sorted. d = {1:'first', -5 : 'negative 5', 6:'six', 99:'ninety-nine', 3:'three'} keys = d.keys() keys.sort() vals = map(d.get, keys) At this point keys is sorted [-5,

Re: Create dict from two lists

2006-02-10 Thread Xavier Morel
Diez B. Roggisch wrote: > py wrote: > >> I have two lists which I want to use to create a dictionary. List x >> would be the keys, and list y is the values. >> >> x = [1,2,3,4,5] >> y = ['a','b','c','d','e'] >> >> Any suggestions? looking for an efficent simple way to do this...maybe >> i am jus

Re: Create dict from two lists

2006-02-10 Thread Paul McGuire
"py" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have two lists which I want to use to create a dictionary. List x > would be the keys, and list y is the values. > > x = [1,2,3,4,5] > y = ['a','b','c','d','e'] > > Any suggestions? looking for an efficent simple way to do this.

Re: Create dict from two lists

2006-02-10 Thread Carsten Haese
On Fri, 2006-02-10 at 08:51, py wrote: > I have two lists which I want to use to create a dictionary. List x > would be the keys, and list y is the values. > > x = [1,2,3,4,5] > y = ['a','b','c','d','e'] > > Any suggestions? looking for an efficent simple way to do this...maybe > i am just havi

Re: Create dict from two lists

2006-02-10 Thread Diez B. Roggisch
py wrote: > I have two lists which I want to use to create a dictionary. List x > would be the keys, and list y is the values. > > x = [1,2,3,4,5] > y = ['a','b','c','d','e'] > > Any suggestions? looking for an efficent simple way to do this...maybe > i am just having a brain fart...i feel lik