[Tutor] verb conjugations

Peter Otten __peter__ at web.de
Sun Aug 25 10:48:51 CEST 2013


Duri Denoth wrote:

> Hello Tutor
> 
> I have written a program that generates verb conjugations.
> 
> There is a loop that generates the regular forms:
> 
> for i in range(6):
>     present[i] = stem + worded_present_ar[i]

An alternative way to write this is

present = [stem + suffix for suffix in worded_present_ar]

> For irregular verbs the correct form is set individually:
> 
> present[2] = stem + worded_present_rule_7[2]

Does this mean that all forms but the 3rd person singular are regular? You 
could set up a dictionary

irregular_forms = {
    "go": {2: "{}es"},
    "be": {0: "am", 1: "are", 2: "is", ..., 5: "are"},
    ...
}
present = ... # preload with regular forms
if stem in irregular_forms:
    for numerus_person, template in irregular_forms[stem].items():
        present[numerus_person] = template.format(stem)

Use of format() instead of concatenation with '+' allows you to build forms 
that don't start with the stem.

> This dosen't seem to me the best readable Python code. Is there any python
> language feature more suitable for this problem?

I don't think readability is the issue with your code; rather the problem is 
to cover all the irregularities of a natural language. 




More information about the Tutor mailing list