String argument -> name of list?

Emile van Sebille emile at fenx.com
Sat Nov 3 12:12:17 EST 2001


"Gustaf Liljegren" <gustafl at algonet.se> wrote in message
news:Xns914EB6E8E8EB7gustaflalgonetse at 195.100.94.182...
> I'm making a program for training musical scales. It should for example be
> able to ask things like: "What is the name of the sixth chord in the F#
> Phrygian scale?".
>
> I have a list of scale names that looks like this:
<snip>
How about:
scales = {
  'ionian'      :[0, 2, 2, 1, 2, 2, 2],
  'dorian'      :[0, 2, 1, 2, 2, 2, 1],
  'phrygian'    :[0, 1, 2, 2, 2, 1, 2],
  'lydian'      :[0, 2, 2, 2, 1, 2, 2],
  'mixolydian'  :[0, 2, 2, 1, 2, 2, 1],
  'aeolian'     :[0, 2, 1, 2, 2, 1, 2],
  'locrian'     :[0, 1, 2, 2, 1, 2, 2]
}

>
> The program chooses one of the scales randomly, so I may get for example
> the string 'dorian' in one session and the string 'locrian' in the next.
>

import random
scale = random.choice(scales.keys())

> Finally, there's a function that should take any of the lists of scale
> structures as an argument. Or perhaps it's better if it takes a string
> value, but it's currently taking the list. Anyway I choose, the problem is
> to make the conversion from a string ('ionian') to the list name (ionian)
> to get the scale structure.

structure = scales[scale]

>
> I wonder if it is any simple syntax for converting a string to the name of
> a list? Or should I use another structure instead, like a dictionary with
> strings + lists, or a list with strings + lists?
>
> Gustaf


HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list