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)
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
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