Python - Data Structures

Dictionary, tuple

Posted by Rico's Nerd Cluster on February 9, 2019

Dictionary

  • setdefault if value does exist, return the existing value; Otherwise, set the key with a new value.
1
2
3
4
5
counts = {}

value = counts.setdefault("apples", 0)
print(value)   # 0
print(counts)  # {'apples': 0}

Tuple

Python compares tuples lexicalgraphically, meaning, 12 > 10.

1
(12, 8.5, -0.23) > (10, 20.0, -0.01)