Here's an interesting question: Can I use the transFn function to remove items in the value list.
Can this be done by simple assigning the current value a value of null in the translate file? M. On 10/2/07, GTXY20 <[EMAIL PROTECTED]> wrote: > I adjusted so that I get the following so if I do not need to translate a > dictionary I do not call the function transFn: > > def transFn(translatefile): > transfile = open(translatefile, 'r') > records = transfile.read() > transfile.close() > lines = records.split() > transDict = {} > for line in lines: > key, value = line.split(',') > transDict[key] = value > > for key, value in Data.items(): > Data[key] = [ transDict.get(i, i) for i in value ] > > At this point can anyone recommend any python modules that helps to create > reporting and graphing? > > On 10/2/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > > > GTXY20 wrote: > > > > > > This seemed to work: > > > > > > def transFn(c): > > > transfile = open('translate.txt', 'r') > > > records = transfile.read() > > > transfile.close() > > > lines = records.split() > > > transDict = {} > > > for line in lines: > > > key, value = line.split(',') > > > transDict[key] = value > > > try: > > > return transDict[c] > > > except KeyError: > > > return c > > > > Yikes! This is re-reading translate.txt every time transFn() is called, > > i.e. once for every key in data! > > > > Kent > > > > > > > > for key in data.keys(): > > > data[key] = map(transFn, data[key]) > > > > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor