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
Post a Comment