[Tutor] Update values stored as a list in a dictionary with values from another dictionary

GTXY20 gtxy20 at gmail.com
Tue Oct 2 16:59:01 CEST 2007


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 <kent37 at tds.net> 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])
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071002/29dd26ba/attachment.htm 


More information about the Tutor mailing list