-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdicts.py
More file actions
86 lines (62 loc) · 2.46 KB
/
dicts.py
File metadata and controls
86 lines (62 loc) · 2.46 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
########################################dictionaries###################################################
dictionary = {}
dictionary["hi"] = "salute"
print(dictionary)
my_nested_dictionary_favMovies = {
"Dark Knight": {
"favCharacter": "The joker",
"favLine": "Wanna see this pencil dissapear",
},
"Transformers": {
"favCharacter": "Optimus Prime",
},
"Rick & Morty": {
"favCharacter": "Mr.poopy Butthole",
},
}
the_dict_constructor = dict(person="James", gender="male", dob="02/03/1999")
dictionaries_person = {
"name": "Ballerino",
"nick name": "Jamaiquino",
"age": "33",
"race": "Bomboclatian",
"favoriteFood": "lemons",
"favorite_tv_show": "the kardashians",
"petOwned": "cat",
"favorite tv line": "how bowt them grapples",
}
the_clear_method = dictionary.clear()
the_popItem_method = dictionaries_person.popitem()
addingValuesTo_dictionaries = dictionaries_person["hair color"] = "pink"
#adding values
updating_values_inDict = dictionaries_person["race"] = "celestial"
#updated
the_pop_method = dictionaries_person.pop("petOwned")
#removes specific values
the_popItem_method = dictionaries_person.popitem()
#removes last item, some versions only
del dictionaries_person["favoriteFood"] #removes specified
#del dictionaries_person #deletes whole dicts
the_update_method = dictionaries_person.update({"address":"tree-a-dem"})
the_copy_method = dictionaries_person.copy() #copy dicts
the_copy_method2 = dict(dictionaries_person) #copy dicts 2
fromKeys_dict = ("key1","key2","key3")
fromkeys_value = 0
the_from_keys_method = dict.fromkeys(fromKeys_dict,fromkeys_value)
print(the_from_keys_method) # this method gives the same value to all keys
print_dict_keys = dictionaries_person["age"] #33
the_get_method = dictionaries_person.get("Hair color")# pink
for print_all_keys in dictionaries_person:
print(print_all_keys+"<<<<<<<<<<<<")
for print_all_values in dictionaries_person:
print(dictionaries_person[print_all_values])
for use_values_method in dictionaries_person.values():
print(use_values_method)
for keys_items, values_items in dictionaries_person.items():
print(keys_items, values_items)
if "age" in dictionaries_person:
print("age exist in dictionaries_person")
the_length_method = len(dictionaries_person)
print("The length is-->>>>>>>><<<", the_length_method)
print(the_dict_constructor)
print("####################################################################")