Skip to content

Commit 19458c5

Browse files
authored
Merge pull request #121 from lironmiz/unit8-Ex8.3.1
Create unit8_ex8.3.1.py
2 parents 2dac319 + 33f6936 commit 19458c5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

unit8_ex8.3.1.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# exercise 8.3.1 from unit 8
2+
'''
3+
given the dict:
4+
my_dict = {(1, 2): 1, (2, 3): 2}
5+
6+
Here are four pieces of code. Choose the output obtained by running each of the code segments.
7+
8+
'''
9+
# 1:
10+
11+
my_dict = {(1, 2): 1, (2, 3): 2}
12+
13+
for key in my_dict.keys():
14+
print(key)
15+
16+
# Answer: (1,2) and (2,3)
17+
18+
# 2:
19+
20+
for value in my_dict.values():
21+
print(value)
22+
23+
# Answer: 1 and 2
24+
25+
# 3:
26+
27+
print(len(my_dict))
28+
29+
# Answer: 2
30+
31+
# 4:
32+
33+
print(my_dict[1])
34+
35+
# Answer: KeyError
36+
37+
# 5:
38+
39+
print(my_dict[1, 2])
40+
41+
# Answer: 1
42+

0 commit comments

Comments
 (0)