Python - Data Structures

Dict

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}