python - How to convert a file into a dictionary? - Stack Overflow

PHOTO EMBED

Wed Feb 14 2024 18:35:29 GMT+0000 (Coordinated Universal Time)

Saved by @tofufu #python

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

https://stackoverflow.com/questions/4803999/how-to-convert-a-file-into-a-dictionary