Skip to content

Commit b420b37

Browse files
committed
Sorting Lists of Tuples
1 parent 79cd200 commit b420b37

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Tuples/7.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Sorting Lists of Tuples
2+
# We can take advantage of the ability to sort a list of tuples to get a sorted version of a dictionary
3+
4+
# First we sort the dictionary by the key using the items() method and sorted() function
5+
6+
7+
d = {'a' : 10, 'b' : 1, 'c' : 22}
8+
print(d.items())
9+
10+
# Output: dict_items([('a', 10), ('b', 1), ('c', 22)])
11+
12+
print(sorted(d.items()))
13+
14+
# Output: [('a', 10), ('b', 1), ('c', 22)]

0 commit comments

Comments
 (0)