[Tutor] Storing dictionary value, indexed by key, into a variable
dyoo at hashcollision.org
Thu Apr 3 22:52:04 CEST 2014
>> 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
You'll also hear the term "Data Driven Programming" or "Table Driven
Programming" to refer to this idea. For example:
It's a core idea, and definitely worth practicing by fixing the
program. You'll see all that control flow structure dissolve away.
More information about the Tutor