Re: Reading from a file and converting it into a list of lines: code not working

2006-06-06 Thread skip
Girish> I have a text file in the following format: Girish> 1,'a',2,'b' Girish> 3,'a',5,'c' Girish> 3,'a',6,'c' Girish> 3,'a',7,'b' Girish> 8,'a',7,'b' Girish> . Girish> . Girish> . Girish> Now i need to generate 2 things by reading the file: Girish> 1)

Re: Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread John Machin
On 6/06/2006 2:10 PM, Girish Sahani wrote: > I have a text file in the following format: > > 1,'a',2,'b' > 3,'a',5,'c' > 3,'a',6,'c' > 3,'a',7,'b' > 8,'a',7,'b' Check out the csv module. > . > . > . > Now i need to generate 2 things by reading the file: > 1) A dictionary with the numbers as keys

Re: Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread K.S.Sreeram
Girish Sahani wrote: > 1) A dictionary with the numbers as keys and the letters as values. > e.g the above would give me a dictionary like > {1:'a', 2:'b', 3:'a', 5:'c', 6:'c' } def get_dict( f ) : out = {} for line in file(f) : n1,s1,n2,s2 = line.split(',') out.upd

Reading from a file and converting it into a list of lines: code not working

2006-06-05 Thread Girish Sahani
I have a text file in the following format: 1,'a',2,'b' 3,'a',5,'c' 3,'a',6,'c' 3,'a',7,'b' 8,'a',7,'b' . . . Now i need to generate 2 things by reading the file: 1) A dictionary with the numbers as keys and the letters as values. e.g the above would give me a dictionary like {1:'a', 2:'b', 3:'a',