Posted on 14th September 2024|18 views
How can I sort a dictionary using a key in python?
Posted on 14th September 2024| views
Just look at this example.
ex_dictionary = {"z": 3, "x": 1, "y": 2}
dictionary_items = ex_dictionary.items()
sorted_items = sorted(dictionary_items)
print(sorted_items)
Output:
[('x', 1), ('y', 2), ('z', 3)]