[Tutor] data structures

Alan Gauld alan.gauld at btinternet.com
Thu Dec 2 09:43:50 CET 2010


"Dana" <dana-s at charter.net> wrote

> I'm using Python to extract words from plain text files.  I have a 
> list of words.  Now I would like to convert that list to a 
> dictionary of features where the key is the word and the value the 
> number of occurrences in a group of files based on the filename

I think I know what you mean but an illustration of the desired
output would be useful. Just to be sure.

> correspond to different categories).  What is the best way to 
> represent this data?  When I finish I expect to have about 70 unique 
> dictionaries with values I plan to use in frequency distributions, 
> etc.  Should I use globally defined dictionaries?

You will either need a class/object to store the data or a set of
global dictionaries (or a database/file I suppose but that only makes
sense if you have a lot of data or need persistence).

You should consider keeping the individual dictionaries in another
dictionary so you only have a single global level variable.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list