Lists and Sublists

dwblas at gmail.com dwblas at gmail.com
Tue Oct 23 18:11:31 EDT 2007


> I am struggling to work out what is the ideal Python data structure
> for the above.  Any help would be greatly appreciated.

The normal way is to use a dictionary of lists.  The key would be the
dictionary key, which would contain a list or a list of lists, that is
each name would be an element of the list unless the name is more than
one word, in which case each name would be converted to a list and
appended to the key.  Some pseudo-code
if key in name_dic:
   name_dic[key] += [name]      ## converted to list
If this doesn't work, then SQLite can be used in memory.  There are
examples on the website.




More information about the Python-list mailing list