-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_dictionary.py
More file actions
41 lines (31 loc) · 771 Bytes
/
11_dictionary.py
File metadata and controls
41 lines (31 loc) · 771 Bytes
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
#Dictionaries are used to store data values in key:value pairs.
#A dictionary is a collection which is ordered*, changeable and do not allow duplicates.
first_dict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964,
"year": 2020,
"colors": ["red", "white", "blue"]
}
print(first_dict)
#Print the "brand" value of the dictionary:
print(first_dict['brand'])
#Check length
print(len(first_dict))
#Check type
print(type(first_dict))
#Print only items
print(first_dict.items())
#Print only only keys
print(first_dict.keys())
#Print only only values
print(first_dict.values())
#update values from a key
first_dict["year"] = 2025
print(first_dict)
#Remove key
del first_dict["year"]
print(first_dict)
#Clear dictionary
first_dict.clear()
print(first_dict)