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

Fix bug in test to ex. 4 #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 6 input_output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1216,9 +1216,9 @@
"tags": []
},
"source": [
"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",
"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",
"\n",
"For example, given the `english.csv` file:\n",
"For example, given the `english.txt` file:\n",
"\n",
"```\n",
"bread\n",
Expand All @@ -1244,7 +1244,7 @@
" 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",
" </li>\n",
" <li>\n",
" 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",
" 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",
" </li>\n",
" </ul>\n",
"<div>\n"
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions 14 tutorial/tests/test_input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,20 @@ def test_exercise3(function_to_test):
def reference_solution_exercise4(
english: pl.Path, dictionary: pl.Path
) -> list[tuple[str, str]]:
with english.open("r") as english_file:
english_reader = csv.reader(english_file)
english_words = [w for w, _ in english_reader]
english_words = english.read_text().splitlines()

with dictionary.open("r") as dict_file:
dict_reader = csv.reader(dict_file)
next(dict_reader)
translations = {en: it for _, it, en, _ in dict_reader}
next(dict_reader) # skip header
translations = {en: it for _, it, en in dict_reader}

return [(e, translations[e]) for e in english_words if e in translations.keys()]
return [
(word, translations[word]) for word in english_words if word in translations
]


def test_exercise4(function_to_test):
words = get_data("english.csv")
words = get_data("english.txt")
dictionary = get_data("dict.csv")
assert function_to_test(words, dictionary) == reference_solution_exercise4(
words, dictionary
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.