forked from UnitTestBot/UTBotJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdicts.py
More file actions
29 lines (23 loc) · 819 Bytes
/
dicts.py
File metadata and controls
29 lines (23 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from typing import List, Dict, Optional
class Word:
def __init__(self, translations: Dict[str, str]):
self.translations = translations
def keys(self):
return list(self.translations.keys())
class Dictionary:
def __init__(
self,
languages: List[str],
words: List[Dict[str, str]],
):
self.languages = languages
self.words = [Word(translations) for translations in words]
def translate(self, word: str, language: Optional[str]):
if language is not None:
for word_ in self.words:
if word_.translations[language] == word:
return word_
else:
for word_ in self.words:
if word in word_.translations.values():
return word_