I am new to python programming. I have come across this line of codes to sort a dict by value (Python 2.4 or greater):
for key, value in sorted(mydict.iteritems(), key=lambda (k,v): (v,k)): print "%s: %s" % (key, value)
Please help me to understand the utility of using a function(here lambda function) inside another function using argument 'key'.
Thanks in advance!
sorted: most common uses are ascending and descending order. in your example you are sorting a dictionary, for which ascending and descending doesn't mean anything. the lambda givessortedthe power to sort anything, the way you want