Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8ecacb0

Browse filesBrowse files
authored
Fix bug in test to I/O exercise 4 (empa-scientific-it#129)
1 parent 98d1107 commit 8ecacb0
Copy full SHA for 8ecacb0

File tree

Expand file treeCollapse file tree

3 files changed

+10
-10
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+10
-10
lines changed

‎input_output.ipynb

Copy file name to clipboardExpand all lines: input_output.ipynb
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,9 +1216,9 @@
12161216
"tags": []
12171217
},
12181218
"source": [
1219-
"Write a function which takes the words from the `english.csv` and translates them to italian using the dictionary file `dict.csv`. The output should be a **list of tuples** with the pair `italian, english` if the word is found and nothing otherwise.\n",
1219+
"Write a function which takes the words from the file `english.txt` and translates them to Italian using the dictionary file `dict.csv`. The output should be a **list of tuples** with the pair `italian, english` if the word is found and nothing otherwise.\n",
12201220
"\n",
1221-
"For example, given the `english.csv` file:\n",
1221+
"For example, given the `english.txt` file:\n",
12221222
"\n",
12231223
"```\n",
12241224
"bread\n",
@@ -1244,7 +1244,7 @@
12441244
" Try to avoid loading the dictionary more than once. <b>\"Dictionary file\"</b> should suggest you the correct Python data structure to use to store the translations.\n",
12451245
" </li>\n",
12461246
" <li>\n",
1247-
" The path to the input file <code>english.csv</code> is available as the argument <code>english</code> of the function <code>solution_exercise4</code>, the file <code>dict.csv</code> as the argument <code>dictionary</code>.\n",
1247+
" The path to the input file <code>english.txt</code> is available as the argument <code>english</code> of the function <code>solution_exercise4</code>, the file <code>dict.csv</code> as the argument <code>dictionary</code>.\n",
12481248
" </li>\n",
12491249
" </ul>\n",
12501250
"<div>\n"
File renamed without changes.

‎tutorial/tests/test_input_output.py

Copy file name to clipboardExpand all lines: tutorial/tests/test_input_output.py
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,20 @@ def test_exercise3(function_to_test):
139139
def reference_solution_exercise4(
140140
english: pl.Path, dictionary: pl.Path
141141
) -> list[tuple[str, str]]:
142-
with english.open("r") as english_file:
143-
english_reader = csv.reader(english_file)
144-
english_words = [w for w, _ in english_reader]
142+
english_words = english.read_text().splitlines()
145143

146144
with dictionary.open("r") as dict_file:
147145
dict_reader = csv.reader(dict_file)
148-
next(dict_reader)
149-
translations = {en: it for _, it, en, _ in dict_reader}
146+
next(dict_reader) # skip header
147+
translations = {en: it for _, it, en in dict_reader}
150148

151-
return [(e, translations[e]) for e in english_words if e in translations.keys()]
149+
return [
150+
(word, translations[word]) for word in english_words if word in translations
151+
]
152152

153153

154154
def test_exercise4(function_to_test):
155-
words = get_data("english.csv")
155+
words = get_data("english.txt")
156156
dictionary = get_data("dict.csv")
157157
assert function_to_test(words, dictionary) == reference_solution_exercise4(
158158
words, dictionary

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.