-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdictbases.py
51 lines (48 loc) · 1.23 KB
/
dictbases.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
39
40
41
42
43
44
45
46
47
48
49
50
51
print("DICTIONARIES")
print("Key/Value pairs, are Unordered")
print("create dicts with {}")
x = {"name":"Rafael", "age":35, "job":"Software Engineer", 10:"Ten"}
print(x, type(x))
del x
print("Create using dict with list of key/value tuples")
x = dict([
("name", "Rafael"),
("age", 35),
("job", "Software engineer")
])
print(x, type(x))
print("Create using dict with named paramets")
x = dict(name="Rafael", age=35, job="Software Engineer")
print(x, type(x))
print("adding or update")
x["name"] = "Rafael Chavez"
x["programming"] = "Python/Go/Node/C++"
x["company"] = "FANG"
print(x)
print("Delete item")
del(x["company"])
print(x)
print("Length ")
print(len(x))
print("Clear items")
x.clear()
print(x)
x = dict(name="Rafael", age=35, job="Software Engineer")
print("Access keys, values and items")
print("Keys")
print(x.keys())
print("Values")
print(x.values())
print("Items (returns list of tuples)")
print(x.items())
print("Check membership only in keys")
print(x, "job", "job" in x)
print("Check membership only in values")
print(x, "Rafael", "Rafael" in x.values())
print("Iterating (Unordered)")
print("Loop using keys")
for k in x:
print(k, x[k])
print("Loop using keys and values (using items)")
for k, v in x.items():
print(k, v)