Program Python untuk Mengurutkan Kamus berdasarkan Nilai

0
(0)

Contoh 1: Urutkan kamus berdasarkan nilai

dt = {5:4, 1:6, 6:3}

sorted_dt = {key: value for key, value in sorted(dt.items(), key=lambda item: item[1])}

print(sorted_dt)

Keluaran

{6: 3, 5: 4, 1: 6}

Contoh 2: Urutkan hanya nilainya

dt = {5:4, 1:6, 6:3}

sorted_dt_value = sorted(dt.values())
print(sorted_dt_value)

Keluaran

[3, 4, 6]

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/breatgem/widiyanata.com/wp-includes/functions.php on line 4755