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.
--
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
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
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
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,
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
"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.
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
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