Canceling out unnecessary punctuation I have 25 branches but I'm only allowed to have 12 branches maximum. The objective of this task was to cancel out unnecessary punctuation, find the common elements that exist in the sentence and dictionary and then to translate the result into English into the other language or the other language to English, depending on what we are given. How do I lessen the number of branches of code I have?

sentence = "?hello boolean bring, !mango! and, country ban,ana wish yum  apple!" 
dictionary = "a aa apple banana pear strawberry mango country wish boolean bring" 
punctuation = "?!," 
language = "English"

"""answer = buwulean bringah mango countryeeh wishey apple"""

"""The above lines aren't in my final code, this is just for information 
about what I'm trying to solve for.""" 

def translate(sentence, dictionary, punctuation, language):
    """R"""

    sentence = ' '.join([x.strip(punctuation) for x in sentence.split()]) 
    """Removing unnecessary punctuation"""  

    dictionary = dictionary.split()
    sentence = sentence.split()
    result = []

    for element in sentence:
        if element in dictionary:
            result.append(element)

    result2 = []

    for word in result:
        if language == "English":
            if word[-1] == "y":
                word = "{}eeh".format(word)
                result2.append(word)
            elif word[-3:] == "ing":
                word = "{}ah".format(word)
                result2.append(word)
            elif word[-2:] == "sh":
                word = "{}ey".format(word) 
                result2.append(word)
            elif "oo" in word:
                word = word.replace("oo", "uwu")
                result2.append(word)
            elif word == "is":
                word = "oy"
                result2.append(word)
            elif word == "are":
                word = "argh"
                result2.append(word)
            elif word == "he" or word == "she" or word == "it":
                word = "hana"
                result2.append(word)
            elif word == "his" or word == "her":
                word = "hami"
                result2.append(word)
            elif word == "ham" or word == "sausage" or word == "bacon":
                word = "{}!".format(word)
                result2.append(word)        
        else:
            if word[-3:] == "eeh":
                word = word[:-3]
                result2.append(word)
            elif word[-2:] == "ah":
                word = word[:-2]
                result2.append(word)
            elif word[-2] == "ey":
                word = word[:-2]
                result2.append(word)
            elif "uwu" in word:
                word = word.replace("uwu", "oo")
                result2.append(word)
            elif word == "oy":
                word = "is"
                result2.append(word)
            elif word == "argh":
                word = "are"
                result2.append(word)
            elif word == "hana":
                word = "he"
                result2.append(word)
            elif word == "hami":
                word = "his"
                result2.append(word)
            elif word == "ham!":
                word = "ham"
                result2.append(word)
            elif word == "sausage!":
                word = "sausage"
                result2.append(word)
            elif word == "bacon!":
                word = "bacon"
                result2.append(word)
            else:
                result2.append(word)
    return " ".join(result2)

translated = translate(sentence, dictionary, punctuation, language)
print(translated)

"""The last two lines are also not in my final code"""
Focusing on the specific part of the code that handles translations for English, here's a way of doing it with a dictionary and a function table:

english_swaps = {
    # Dictionary of 1:1 word replacements.
    "is": "oy",
    "are": "argh",
    "he": "hana",
    "she": "hana",
    "it": "hana",
    "his": "hami",
    "her": "hami",
    "ham": "ham!",
    "sausage": "sausage!",
    "bacon": "bacon!",
}

english_rules = [
    # List of arbitrary functions to transform a word.
    lambda w: f"{w}eeh" if w[-1] == "y" else None,
    lambda w: f"{w}ah" if w[-3:] == "ing" else None,
    lambda w: f"{w}ey" if w[-2:] == "sh" else None,
    lambda w: w.replace("oo", "uwu") if "oo" in w else None,
    lambda w: english_swaps.get(w, None),
]

def translate(word: str) -&gt; str:
    if language == "English":
        for rule in english_rules:
            # Attempt to apply each rule in turn, using the first one to match.
            translated = rule(word)
            if translated is not None:
                return translated
        return word
    else:
        # ...

print(" ".join(
    translate(w) for w in "he is eating sausage and loving every bit of it".split()
))
# prints: hana oy eatingah sausage! and lovingah everyeeh bit of hana


You could apply this same pattern to have a dictionary and function table for each language, and put those into another dictionary that maps each language to a function table, so that ultimately you could do something like:

for rule in rules[language]:
   translated = rule(word)
   ... etc ...