-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python_Dictionaries.py
60 lines (46 loc) · 2.35 KB
/
Python_Dictionaries.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
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'] = '[email protected]'
emails['craig'] = '[email protected]'
emails['elizabeth'] = '[email protected]'
assert emails == {
"ashley": "[email protected]",
"craig": "[email protected]",
"elizabeth": "[email protected]",
}, f"Expected `emails` to be {{'ashley': '[email protected]', 'craig': '[email protected]', 'elizabeth': '[email protected]'}} but got: {repr(emails)}"
# 3) Remove 'craig' from the emails dictionary without reassigning the variable.
del emails['craig']
assert emails == {
"ashley": "[email protected]",
"elizabeth": "[email protected]",
}, f"Expected `emails` to be {{'ashley': '[email protected]', 'elizabeth': '[email protected]'}} but got: {repr(emails)}"
# 4) Add 'dalton' to the emails dictionary without reassigning the variable.
emails['dalton'] = '[email protected]'
assert emails == {
"ashley": "[email protected]",
"elizabeth": "[email protected]",
"dalton": "[email protected]",
}, f"Expected `emails` to be {{'ashley': '[email protected]', 'elizabeth': '[email protected]', 'dalton': '[email protected]'}} 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 == [
], f"Expected `email_list` to be ['[email protected]', '[email protected]', '[email protected]'] 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", "[email protected]"),
("elizabeth", "[email protected]"),
("dalton", "[email protected]"),
], f"Expected `pairs` to be [('ashley', '[email protected]'), ('elizabeth', '[email protected]'), ('dalton', '[email protected]')] but got: {repr(pairs)}"