+ 3
Hello. Can I get help about sort an output of a dict by value
For example sort output of code below by "n3" value: dictionary1 = { "a" : {"n1": 0, "n2": 5, "n3": 9}, "b" : {"n1": 5, "n2": 4, "n3": 2}, "c" : {"n1": 2, "n2": 6, "n3": 0}, "d" : {"n1": 7, "n2": 3, "n3": 1}, }
4 Réponses
+ 9
Can you try this:
for i in sorted(dictionary1.items(), key=lambda kv: kv[1]['n3']):
print(*i)
https://code.sololearn.com/c492FReZA2EF/?ref=app
+ 5
ok - can you show us a sample how the output should look like? Thanks!
+ 1
Output should be like string below:
c = n1: 2, n2 : 6, n3 : 0
d = n1: 7, n2 : 3, n3 : 1
b = n1: 5, n2 : 4, n3 : 2
a = n1: 0, n2 : 5, n3 : 9
Thanks 👍
+ 1
Thank you Lothar.
Amazing