spohle wrote:
> hi i have a normal dictionary with key and value pairs. now i wanna
> sort by the keys BUT in a specific order i determine in a list !? any
> ideas
>
> dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
>
> list = [key2, key3, key1]
>
You could use the seqdict package at
spohle a écrit :
> how do i get the result back into the dictionary ?
>
Python dicts (like almost any known hash-table) are *not* ordered. If
you need an ordered dict, roll your own - this is quite easy.
--
http://mail.python.org/mailman/listinfo/python-list
Tim Chase a écrit :
(snip)
>
>> list = [key2, key3, key1]
>
> 1) it's bad practice to shadow the list() command...
s/command/type/
> funky stuff can happen.
indeed, if you shadow it with a non-compatible object !-)
--
http://mail.python.org/mailman/listinfo/python-list
i write the dict out to a file, not with file methods but rather with
an inhouse python code. unfortunatly the order plays a big role for
that.
--
http://mail.python.org/mailman/listinfo/python-list
> how do i get the result back into the dictionary ?
Well, if you must, if you've just got the results in my
previous post, you can take them and shove them back into a
dict with
results = [('key1','value1'),('key2','value2)]
newDict = dict(results)
If you're not doing anything
how do i get the result back into the dictionary ?
--
http://mail.python.org/mailman/listinfo/python-list
"spohle" <[EMAIL PROTECTED]> writes:
> dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
>
> list = [key2, key3, key1]
Is this what you want?
dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
keys = ['key2', 'key3', 'key1']
items = [dic[k] for k in keys]
print ite
> hi i have a normal dictionary with key and value pairs. now i wanna
> sort by the keys BUT in a specific order i determine in a list !? any
> ideas
>
> dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
>
> list = [key2, key3, key1]
1) it's bad practice to shadow the list() command...f
hi i have a normal dictionary with key and value pairs. now i wanna
sort by the keys BUT in a specific order i determine in a list !? any
ideas
dic = {'key1':'value1', 'key2':'value2', 'key3':'value3'}
list = [key2, key3, key1]
--
http://mail.python.org/mailman/listinfo/python-list