String argument -> name of list?

Sean 'Shaleh' Perry shalehperry at
Sat Nov 3 18:08:13 CET 2001

> 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?

from your description a dictionary is exactly what you want.

scales['ionian'] would give you [0, 2, 2, 1, 2, 2, 2].  You could then use
random.choice(scales.keys()) to get a random name.

The only time this could be a problem is if you care about the order of the
names.  Then you will have code like:

print scales['ionian']
print scales['dorian']
print scales['locrian']

instead of looping over the names.

More information about the Python-list mailing list