DEV Community

Discussion on: Daily Challenge #307 - Spanish Conjugator

Collapse
 
agtoever profile image
agtoever • Edited

Nice answer. Here is a suggestion that gets rid of the duplicate code by putting the verb endings in a dict and using a comprehension to give the result:

def conjugate(verb):
    verb = verb.lower()
    conj = {
        'ar': ['o', 'as', '', 'amos', 'ais', 'an'],
        'er': ['o', 'es', '', 'emos', 'eis', 'en'],
        'ir': ['o', 'es', 'e', 'imos', 'is', 'en']
    }
    return [verb[:-2] + c if len(c) > 0 else verb[:-1] + c for c in conj[verb[-2:]]]
Enter fullscreen mode Exit fullscreen mode