-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython_Dictionaries.py
More file actions
60 lines (46 loc) · 2.35 KB
/
Python_Dictionaries.py
File metadata and controls
60 lines (46 loc) · 2.35 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
# 1) Set the emails variable to be an empty dictionary
emails ={}
assert emails == {}, f"Expected `emails` to be {{}} but got: {repr(emails)}"
# 2) Add 'ashley', 'craig', and 'elizabeth' to the emails dictionary without reassigning the variable.
emails['ashley'] = 'ashley@example.com'
emails['craig'] = 'craig@example.com'
emails['elizabeth'] = 'elizabeth@example.com'
assert emails == {
"ashley": "ashley@example.com",
"craig": "craig@example.com",
"elizabeth": "elizabeth@example.com",
}, f"Expected `emails` to be {{'ashley': 'ashley@example.com', 'craig': 'craig@example.com', 'elizabeth': 'elizabeth@example.com'}} but got: {repr(emails)}"
# 3) Remove 'craig' from the emails dictionary without reassigning the variable.
del emails['craig']
assert emails == {
"ashley": "ashley@example.com",
"elizabeth": "elizabeth@example.com",
}, f"Expected `emails` to be {{'ashley': 'ashley@example.com', 'elizabeth': 'elizabeth@example.com'}} but got: {repr(emails)}"
# 4) Add 'dalton' to the emails dictionary without reassigning the variable.
emails['dalton'] = 'dalton@example.com'
assert emails == {
"ashley": "ashley@example.com",
"elizabeth": "elizabeth@example.com",
"dalton": "dalton@example.com",
}, f"Expected `emails` to be {{'ashley': 'ashley@example.com', 'elizabeth': 'elizabeth@example.com', 'dalton': 'dalton@example.com'}} but got: {repr(emails)}"
# 5) Return a list of keys from the emails dictionary as `users`
users = list(emails.keys())
assert users == [
"ashley",
"elizabeth",
"dalton",
], f"Expected `users` to be ['ashley', 'elizabeth', 'dalton'] but got: {repr(users)}"
# 6) Return a list of values from the emails dictionary as `email_list`
email_list = list(emails.values())
assert email_list == [
"ashley@example.com",
"elizabeth@example.com",
"dalton@example.com",
], f"Expected `email_list` to be ['ashely@example.com', 'elizabeth@example.com', 'dalton@example.com'] but got: {repr(email_list)}"
# 7) Return a list of tuples called `pairs` representing the key/value pairs in `emails`.
pairs = list(emails.items())
assert pairs == [
("ashley", "ashley@example.com"),
("elizabeth", "elizabeth@example.com"),
("dalton", "dalton@example.com"),
], f"Expected `pairs` to be [('ashley', 'ashley@example.com'), ('elizabeth', 'elizabeth@example.com'), ('dalton', 'dalton@example.com')] but got: {repr(pairs)}"