<jupyter_start><jupyter_text>Factory Method<jupyter_code>class Latin_to_English:
    def __init__(self):
        self.lexicon = {'veni': 'I came',
                        'vidi' : 'I saw',
                        'vici' : 'I conquered'}
    def translate(self, word):
        return self.lexicon.get(word, 'not in lexicon')
    
class English_to_Latin:
    def __init__(self):
        self.lexicon = {'without': 'sine',
                        'which' : 'qua',
                        'not' : 'non'}
    def translate(self, word):
        return self.lexicon.get(word, 'not in lexicon')    
def Translator(language):
    translation = {
        'english' : English_to_Latin,
        'latin' : Latin_to_English
    }
    return translation[language]()
eng = Translator('english')
for word in ['without', 'which', 'not']:
    print(eng.translate(word))

lat = Translator('latin')
for word in ['veni', 'vidi', 'vici']:
    print(lat.translate(word))<jupyter_output>I came
I saw
I conquered
{'fraction_non_alphanumeric': 0.140973630831643, 'fraction_numerical': 0.0, 'mean_word_length': 2.463157894736842, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '335327', 'license': 'MIT', 'n_tokens_mistral': 331, 'n_tokens_neox': 316, 'n_words': 74, 'path': 'Section 11/11.1-factory.ipynb', 'repo_name': 'PacktPublishing/The-Modern-Python-Challenge-v-', 'size': '986'}