Tuple creation, unpacking, and ordering [ref]
Problem¶
- Create a one-element tuple containing
5. - Unpack
(2, 7)intostartandend. - Compare
(2, 3)with(2, 5). - Sort
[(2, "b"), (1, "z"), (2, "a")]naturally. - Prepend
"word"to("one", "two")using unpacking.
Python solution¶
(5,) # (5,)
start, end = (2, 7)
(start, end) # (2, 7)
(2, 3) < (2, 5) # True
sorted([(2, "b"), (1, "z"), (2, "a")])
# [(1, 'z'), (2, 'a'), (2, 'b')]
suffix = ("one", "two")
("word", *suffix) # ('word', 'one', 'two')
Links¶
- 155. Min Stack (Top Easy)
- 347. Top K Frequent Elements (Top Medium)
- 140. Word Break II (Top Hard)
- 218. The Skyline Problem (Top Hard)