problem with dictionaries within lists

Terry Reedy tjreedy at udel.edu
Wed Sep 25 11:34:29 EDT 2002


Two code comments:

Using 'list' and 'dict' as a variable names will bite when you want to
use the builtin functions someday.  I'll call them pairs and hdict.

I believe that a huge number of lines like
> rcTN = re.compile('Technical_Knowledge')
etc
...
> elif rcTN.match(list[0]):
> dict['Technical_Knowledge'] = list[1]
etc
could be replaced and sped-up by

headers={'Technical_knowledge':1, etc...} # in 2.3, would use new set
type
...
if pairs[0] in headers:
    hdict[pairs[0]] = pairs[1]

Highly repetitive code like this can usually be nicely condensed by
graceful use of Python lists and dicts.

Terry J. Reedy





More information about the Python-list mailing list