Re: [Tutor] Sorting a dictionary by a value when the values are tuples

2011-03-05 Thread Steven D'Aprano
ranjan das wrote: This is a small example i created from operator import itemgetter temp={'4':(2,3), '2':(5,8)} print temp.items() new_temp=sorted(temp.items(), key=itemgetter(1) print new_temp Another syntax error. Please ensure that you test your code before posting. In this case, it's eas

[Tutor] Sorting a dictionary by a value when the values are tuples

2011-03-05 Thread ranjan das
This is a small example i created from operator import itemgetter temp={'4':(2,3), '2':(5,8)} print temp.items() new_temp=sorted(temp.items(), key=itemgetter(1) print new_temp I want to sort the dictionary by the value in the first element of the tuple ((2,3) and (5,8)) and then the second