A
Afanasiy
This is fairly simple in PHP, how do I do it in Python?
http://www.php.net/manual/en/function.ksort.php
http://www.php.net/manual/en/function.ksort.php
This is fairly simple in PHP, how do I do it in Python?
This is fairly simple in PHP, how do I do it in Python?
http://www.php.net/manual/en/function.ksort.php
Afanasiy:
def ksort(d, func = None):
keys = d.keys()
keys.sort(func)
return keys
for k in ksort(d):
print k, v
As a bonus, you don't need to tell the sort to sort numerically
vs. lexigraphically --- Python's strong typing knows that by
default. You can pass in an alternate compare function if you
want.
Afanasiy:
def ksort(d, func = None):
keys = d.keys()
keys.sort(func)
return keys
for k in ksort(d):
print k, v
Why wouldn't [ksort] be a standard function?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.