+ 1

How to sort a dictionary in Python in ascending order of their values

Plz urgently answer it it may be tough

3rd Dec 2018, 1:34 PM
Tushar Anand
7 Respostas
+ 2
Do you really need the dictionary sorted? Because dictionaries aren't really made for that. Or do you only want to output the values sorted? Then you could just write: print(*sorted(yourdict.values()))
3rd Dec 2018, 2:00 PM
HonFu
HonFu - avatar
+ 1
Was it really a dictionary? And not a list?
3rd Dec 2018, 2:03 PM
HonFu
HonFu - avatar
+ 1
If the talk was really about sorting a Python dictionary I find it quite silly tbh. Somewhat like: 'Please eat your steak cutting with your fork and picking with your knife.'
3rd Dec 2018, 2:07 PM
HonFu
HonFu - avatar
0
No there was a question in class 11 book to sort a dictionary using basic bubble sort method
3rd Dec 2018, 2:01 PM
Tushar Anand
0
That's why it's like a challenge
3rd Dec 2018, 2:02 PM
Tushar Anand
0
Yes a dictionary if you have any doubt you may go through application based questions of ch 10 class 11 sumita arora
3rd Dec 2018, 2:05 PM
Tushar Anand
0
Let's do it anyway. Sorted output at least. score = {'Fred': 56, 'Anna': 102, 'Joe': 35} for i, j in sorted( [(j,i) for (i,j) in score.items()]): print(j+':', i)
3rd Dec 2018, 2:12 PM
HonFu
HonFu - avatar