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

2007-10-02 Thread Ricardo Aráoz
John Fouhy wrote: > On 02/10/2007, GTXY20 <[EMAIL PROTECTED]> wrote: >> Hello all, >> >> Let's say I have the following dictionary: >> >> {1:(a,b,c), 2:(a,c), 3:(b,c), 4:(a,d)} >> >> I also have another dictionary for new value association: >> >> {a:1, b:2, c:3} >> >> How should I approach if I wan

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

2007-10-02 Thread Kent Johnson
GTXY20 wrote: > > I have the transFn function as follows: > > def transFn(translatefile): > transfile = open(translatefile, 'r') > records = transfile.read() > transfile.close() > lines = records.split() > transDict = {} > for line in lines: > key, value = line.spl

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

2007-10-02 Thread GTXY20
I have the transFn function as follows: 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] = valu

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

2007-10-02 Thread Kent Johnson
GTXY20 wrote: > 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? No, that will make the translated value be None (I guess that is what you mea

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

2007-10-02 Thread GTXY20
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

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

2007-10-02 Thread GTXY20
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

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

2007-10-02 Thread Kent Johnson
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[k

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

2007-10-02 Thread Kent Johnson
John Fouhy wrote: > You could use the map function... > > Let's say we have something like: > > transDict = { 'a':1, 'b':2, 'c':3 } > > We could define a function that mirrors this: > > def transFn(c): > try: > return transDict[c] > except KeyError: > return c This coul

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

2007-10-02 Thread GTXY20
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 tran

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

2007-10-02 Thread GTXY20
Sorry - solved my own problem - it was the way I was creating my dictionary and assigning the value as a list. I will post my final working code shortly. M. On 10/2/07, GTXY20 <[EMAIL PROTECTED]> wrote: > > I seem to be encountering a problem and I think it is because I actually > have my data a

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

2007-10-02 Thread GTXY20
I seem to be encountering a problem and I think it is because I actually have my data as follows: data = {1:[a,b,c], 2:[a,c], 3:[b,c], 4:[a,d]} not as previously mentioned: data = {1:(a,b,c), 2:(a,c), 3:(b,c), 4:(a,d)} So the values are actually stored as a list. I am trying to adjust so that

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

2007-10-01 Thread John Fouhy
On 02/10/2007, GTXY20 <[EMAIL PROTECTED]> wrote: > Hello all, > > Let's say I have the following dictionary: > > {1:(a,b,c), 2:(a,c), 3:(b,c), 4:(a,d)} > > I also have another dictionary for new value association: > > {a:1, b:2, c:3} > > How should I approach if I want to modify the first dictionar

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

2007-10-01 Thread GTXY20
Hello all, Let's say I have the following dictionary: {1:(a,b,c), 2:(a,c), 3:(b,c), 4:(a,d)} I also have another dictionary for new value association: {a:1, b:2, c:3} How should I approach if I want to modify the first dictionary to read: {1:(1,2,3), 2:(1,3), 3:(2,3), 4:(1,d)} There is the p