On Fri, 18 Feb 2005 04:18, Richard Terry wrote:
mydict = {}
mydict[0] = line1, line2, line3, line4, line5
if I print out mydict (as you can see I put drug stuff in it) I get this:
{0: (u'', u'omeprazole', u'omeprazole magnesium', u'Losec Tablets',
u'20mg', u'1 mane')}
If you really want to make use of a dictionary data type, you should do like
mydict['drug']='omeprazole'
mydict['strength']='20mg'
What you are doing is using a dictionary as if it was a simple list.
Lists are faster and consume less memory, might even be appropriate.
IN that case you would declare
mylist = []
if "o" is your primary key in the example above, and you want to hold the data
for multiple primary keys in memory, you can use a dictionary of
dictionaries, or a dictonary of lists, or lists of dictionaries etc.
Main difference:
A dictionary is an *unordered* collection of objects. objects are accessed via
a "key"
A list is an *ordered* collection of objects which are accessed through a
numeric index
In Python you have a third similar datatype called a "tuple". This is
essentially the same as a list, only that it is immutable (you cannot add
objects to a tuple, nor delete or modify objects within the tuple). Tuples
provide the fastest and least memory consuming access to object collections.