-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionaries.py
More file actions
43 lines (31 loc) · 1.31 KB
/
dictionaries.py
File metadata and controls
43 lines (31 loc) · 1.31 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
# dictionaries
# What is a dictionary? - Data collection
# It is a bit more dynamic than tuples or lists.
# How? very useful tool within any coding language
# Simple concept of KEY VALUE PAIRS
# Syntax - to create a dictionaries we use {}
# Let's now create an example to learn by doing
# KEY VALUE
student_record = { "name": "Daniel",
"stream": "DevOps",
"completed_lessons": 5,
"completed_lessons_names": ["strings", "tuples", "variables"]
}
for student in student_record:
print(student, ":", student_record[student])
print(student_record)
print(type(student_record))
print(sorted(student_record))
print(student_record.values())
student_record["completed_lessons_names[1]"] = 3
new_list = student_record["completed_lessons_names"]
print(new_list)
# Add 2 topics that we have covered
student_record["completed_lessons_names"].append("Lists")
student_record["completed_lessons_names"].append("built-in methods")
# display the list
print(student_record)
print(student_record["stream"]) # to fetch the value of stream
print(student_record["completed_lessons_names"][1])
print(student_record["completed_lessons_names"][2]) # Using index of 2 to draw the string variables
print(student_record["name"]) # drawing the name variable from the dictionary