[Tutor] How to control list input ?

Alan Gauld alan.gauld at blueyonder.co.uk
Fri Jun 4 14:07:57 EDT 2004


> I thought that the dictionaries would be like this:
>
> Name     ||      key      ||         value
> -----------------------------------------


Actually you just described a relational data schema. You would
almost certainly be better off moving to a proper relatinal
database such as MySQL, Postgres or SqlLite. In the long term
it will be much easier to work with.

> - is it possible for a dictionary to save a class as a value ? Would
> this actually make sense in this case ?

Yes, and more usefully instances of classes.

> Someone also suggests using dictionaries instead of lists:
>
> - is it possible for a dictionary to save another dictionary as a
> value ?

Yes, you can store any object as a value.
Its quite common to have nested dictionaries:


D = { "first" : { "second" : { "third" : 3, "fourth" : 4  },
                  "fifth"  : { "sixth" : 6, "seventh" : 7 }  },
      "eight" : { "short" : 0},
    }

print D['first']['fifth']['seventh']
print D['eighth']['short']

etc...

You will find more on this in the section on collection types
within the Raw Materials topic in my new tutor

HTH

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld/tutor2




More information about the Tutor mailing list