> On 6/06/2006 4:15 PM, Girish Sahani wrote:
>> Really sorry for that indentation thing :)
>> I tried out the code you have given, and also the one sreeram had
>> written.
>> In all of these,i get the same error of this type:
>> Error i get in Sreeram's code is:
>> n1,_,n2,_ = line.split(',')
>> Va
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 4:15 PM, Girish Sahani wrote:
> Really sorry for that indentation thing :)
> I tried out the code you have given, and also the one sreeram had written.
> In all of these,i get the same error of this type:
> Error i get in Sreeram's code is:
> n1,_,n2,_ = line.split(',')
> ValueError: n
Really sorry for that indentation thing :)
I tried out the code you have given, and also the one sreeram had written.
In all of these,i get the same error of this type:
Error i get in Sreeram's code is:
n1,_,n2,_ = line.split(',')
ValueError: need more than 1 value to unpack
And error i get in you
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
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',