[Tutor] Dictionary Keys
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 7 Aug 2002 14:50:31 +0100
> Basically, what do y'all tend to do when you are
> entering/saving information in a dictionary and,
> the way you've set up your script's parameters,
> you could conceivably create key:value combinations
> with identical keys (but different values)?
Dictionary keys are unique so you can't do it!
What you can do is have the value store a list of
items(or even another dictionary). Thus if we have
patient ID as the first key and the value is a
dictionary of visits keyed by date/time we can
generate something like this:
dict = {'Gauld': {20020806:(15,'sore head','$50'),
20020601:(22,'pain in the neck', '$500')},
'Colburn': { 20010102: 47, 'stabbing pain', $5) } }
Thus we could get a list of visit dates for gauld by:
dict['gauld'].keys()
or a particular visits details with:
dict['gauld'][20020806]
or a particular item:
print "Complaint: ", dict['gauld'].[20020806][1]
Does that help?
BTW anything morre complex that this and I'd definitely
suggest moving to a real database. I'd even consider it
for this level if there will be many(>1000) patients/visits.
Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld