forked from karunaket/_Python_
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dictionary.py
38 lines (29 loc) · 900 Bytes
/
dictionary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# dictionary = a collection of {key:value} pairs
# ordered and changeable. No duplicates
capitals = {"USA": "Washington D.C.",
"India": "New Delhi",
"China": "Beijing",
"Russia": "Moscow"}
# USA --> keys
# Washington D.C. --> values
# print(dir(capitals))
# print(help(capitals))
# print(capitals.get("Japan"))
# if capitals.get("Russia"):
# print("That capital exists")
# else:
# print("That capital doesn't exist")
# capitals.update({"Germany": "Berlin"})
# capitals.update({"USA": "Detroit"})
# capitals.pop("China")
# capitals.popitem()
# capitals.clear()
# keys = capitals.keys()
# for key in capitals.keys():
# print(key)
# values = capitals.values()
# for value in capitals.values():
# print(value)
# items = capitals.items()
# for key, value in capitals.items():
# print(f"{key}: {value}")