Skip to content

Commit e4cccbe

Browse files
committed
added dict example
1 parent 1f745f2 commit e4cccbe

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

questions/dict_01.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Lists: What output is produced by this program?"""
1+
"""Dictionaries: What output is produced by this program?"""
22

33
from math import sqrt
44

questions/dict_02.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Dictionaries: How could `fill_dictionary` be implemented?"""
2+
3+
from dict_02_module import fill_dictionary
4+
5+
print(fill_dictionary())

questions/dict_02_module.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Lists: What output is produced by this program?"""
2+
3+
def fill_dictionary() -> dict[int, str]:
4+
"""
5+
Fill a dictionary with some values.
6+
7+
:return: the filled dictionary
8+
"""
9+
a: dict[int, str] = {1: "one", 2: "two", 3: "three",
10+
4: "four", 5: "five"}
11+
a.update({-k: f"minus {v}" for k, v in a.items()})
12+
return a

0 commit comments

Comments
 (0)