>> The thing is, this looks really messy Could anyone give me some pointers
>> on how this could be more elegantly done?
>
> Instead of the many if...elif switches try to put the alternatives into a
> list, e. g.
>
>>>> cases = [
> ... "Nominative",
> ... "Genitive",
> ... "Dative",
> ... "Accusative",
> ... "Ablative"
> ... ]


To restate what Peter is presenting: transforming the control flow
structure of the program (if statements) is the key.  That is, we take
that control flow structure and rephrase it as _data_ structures
(lists, dicts).

You'll also hear the term "Data Driven Programming" or "Table Driven
Programming" to refer to this idea.  For example:

    http://blogs.msdn.com/b/ericlippert/archive/2004/02/24/79292.aspx

It's a core idea, and definitely worth practicing by fixing the
program.  You'll see all that control flow structure dissolve away.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to