Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 19abfb8

Browse files
authoredSep 2, 2022
Merge pull request #122 from jetbrains-academy/sofia/add_dict_task
feat(task): add dictionary items from lists task
2 parents d694c37 + 533dc87 commit 19abfb8

File tree

7 files changed

+52
-0
lines changed

7 files changed

+52
-0
lines changed
 

‎Data structures/Add Items from lists/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
list_of_keys = ["key1", "key2", "key3"]
2+
list_of_values = [100, 200, 300]
3+
4+
my_dict = {}
5+
for x in range(len(list_of_keys)):
6+
my_dict[list_of_keys[x]] = list_of_values[x]
7+
8+
print(my_dict.items())
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type: edu
2+
files:
3+
- name: lists_to_dict.py
4+
visible: true
5+
placeholders:
6+
- offset: 126
7+
length: 44
8+
placeholder_text: '# TODO: populate the dictionary with key:value pairs from the
9+
lists'
10+
- name: tests/test_task.py
11+
visible: false
12+
- name: __init__.py
13+
visible: false
14+
- name: tests/__init__.py
15+
visible: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Add dictionary items from lists
2+
3+
We defined two lists and an empty dictionary for you. Your task is to
4+
iterate over the lists using a `for` loop and add key:value pairs of
5+
the corresponding list items (key1: 100, key2: 200, key3: 300) to the dictionary.
6+
7+
<div class="hint">
8+
9+
Make use of list indexing such as `list_name[index]` and dictionary indexing such as `dict[key] = value` for value assignment.
10+
</div>

‎Data structures/Add Items from lists/tests/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import unittest
2+
3+
from lists_to_dict import my_dict
4+
5+
6+
# todo: replace this with an actual test
7+
class TestCase(unittest.TestCase):
8+
9+
def test_dict(self):
10+
list_of_keys = ["key1", "key2", "key3"]
11+
list_of_values = [100, 200, 300]
12+
13+
test_dict = {}
14+
for x in range(len(list_of_keys)):
15+
test_dict[list_of_keys[x]] = list_of_values[x]
16+
17+
self.assertEqual(test_dict, my_dict, msg="my_dict seems off.")

‎Data structures/lesson-info.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ content:
66
- Tuples
77
- Join method
88
- Dictionaries
9+
- Add Items from lists
910
- Dictionary keys() and values()
1011
- Dictionary keys
1112
- In keyword

0 commit comments

Comments
 (0)
Please sign in to comment.