def get_pair(line):
key, sep, value = line.strip().partition(" ")
return int(key), value
with open("file.txt") as fd:
d = dict(get_pair(line) for line in fd)
d = {}
with open("file.txt") as f:
for line in f:
(key, val) = line.split()
d[int(key)] = val