Re: [python-win32] How to replace the values with keys ?

2008-07-24 Thread Tim Roberts
Graps Graps wrote: aDict is a dictionary, containing {0: 'str1\n', 1: 'str22\n', 2: 'str3\n', 3: 'str4\n', 4: 'str5\n', ..., , 1308: 'str1309\n'}. Are you saying that string is exactly what is in the file aDict.py? In that case, you can't import it. The expression will be

Re: [python-win32] How to replace the values with keys ?

2008-07-23 Thread Tim Roberts
Graps Graps wrote: Hi all, I tried import aDict import re infile = open('text1.txt','rw') outfile = open('text3.txt','w') def replace_words(infile, aDict): rc=re.compile('|'.join(map(re. escape, aDict))) def translate(match): return aDict[match.group(0)] return

Re: [python-win32] How to replace the values with keys ?

2008-07-23 Thread Graps Graps
Hi all, aDict is a dictionary, containing {0: 'str1\n', 1: 'str22\n', 2: 'str3\n', 3: 'str4\n', 4: 'str5\n', ..., , 1308: 'str1309\n'}. I used: keys = m values = noDupes aDict = dict(zip(keys,values)) to get aDict, where m=range(1309) and noDupes was a list read from a text file.

[python-win32] How to replace the values with keys ?

2008-07-22 Thread Graps Graps
Hi all, I am a newbie to python... I have two text files text1 and text2. Text1 is a tabbed separated file, say like a b a c a d a g b c b d b h c d c h... and so on.. Text2 is a python dictionary containing data as {0: 'a', 1: 'b', 2: 'c'...} now I want the data in text1 to be replaced with

Re: [python-win32] How to replace the values with keys ?

2008-07-22 Thread Larry Bates
Graps Graps wrote: Hi all, I am a newbie to python... I have two text files text1 and text2. Text1 is a tabbed separated file, say like a b a c a d a g b c b d b h c d c h... and so on.. Text2 is a python dictionary containing data as {0: 'a', 1: 'b', 2: 'c'...} now I want the data in

Re: [python-win32] How to replace the values with keys ?

2008-07-22 Thread Tim Roberts
Graps Graps wrote: Hi all, I am a newbie to python... I have two text files text1 and text2. Text1 is a tabbed separated file, say like a b a c a d a g b c b d b h c d c h... and so on.. Text2 is a python dictionary containing data as {0: 'a', 1: 'b', 2: 'c'...} now I want the data in

Re: [python-win32] How to replace the values with keys ?

2008-07-22 Thread Graps Graps
Hi all, I tried import aDict import re infile = open('text1.txt','rw') outfile = open('text3.txt','w') def replace_words(infile, aDict): rc=re.compile('|'.join(map(re.escape, aDict))) def translate(match): return aDict[match.group(0)] return rc.sub(translate, infile)