def sort_fun(a, b):
# compare as integers
return (-1)*cmp(int(a), int(b))
my_dict={2:'m', 1:'z', 3:'a'}
print my_dict
my_keys=my_dict.keys()
my_keys.sort()
print "my_keys_asc_sort =%s" %my_keys
my_keys.sort(sort_fun)
print "my_keys_desc_sort =%s" %my_keys
for key in my_keys:
print "%s:%s" % (key, my_dict[key])
[EMAIL PROTECTED]
Sent by: [EMAIL PROTECTED]
10.10.2007 11:33
Please respond to
Konference PyCZ <[email protected]>
To
Konference PyCZ <[email protected]>
cc
Subject
Re: [python] Jak setridit dictionary
Ak chces triedit kluce podla nejakej funkcie, tak asi takto:
def sort_fun(a, b):
# compare as integers
return (-1)*cmp(int(a), int(b))
my_dict={2:'m', 1:'z', 3:'a'}
print my_dict
my_keys=my_dict.keys()
my_keys.sort()
print "my_keys_asc_sort =%s" %my_keys
my_keys.sort(sort_fun)
print "my_keys_desc_sort =%s" %my_keys
"Ondrej Beran" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
10.10.2007 11:01
Please respond to
Konference PyCZ <[email protected]>
To
[email protected]
cc
Subject
[python] Jak setridit dictionary
Ahoj vsichni,
mam dictionary napr. {1:'z', 2:'m', 3:'a', ....} a potreboval bych k
nemu vytvorit neco jako index setrideny podle hodnoty, napr.
[3,2,1,...], abych mohl s polozkami v dicitionary pracovat v poradi
danem tim indexem.
Ale nenapada mi, jak to udelat... Poradi mi nekdo?
Diky, Ondrej
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python
Mgr. Ing. Roman MIKLÓŠ
Prvá stavebná sporiteľňa a.s.
Bajkalská 30, P. O. Box 48
829 48 Bratislava 25
Tel.: +421/ 2 / 582 31 174
Fax: +421/ 2 / 582 31 109
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python
Mgr. Ing. Roman MIKLÓŠ
Prvá stavebná sporiteľňa a.s.
Bajkalská 30, P. O. Box 48
829 48 Bratislava 25
Tel.: +421/ 2 / 582 31 174
Fax: +421/ 2 / 582 31 109
_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python