Python - file to dictionary? -


i have file comprising 2 columns, i.e.,

1  2 b  3 c 

i wish read file dictionary such column 1 key , column 2 value, i.e.,

d = {1:'a', 2:'b', 3:'c'} 

the file small, efficiency not issue.

thanks, s.

d = {} open("file.txt") f:     line in f:        (key, val) = line.split()        d[int(key)] = val 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -