+ 2
How to make a dictionary from a .txt files
i have .txt file with format like this a:1 b:2 c:3 d:4 e:5 how can i make dictionary from files like that? if i have many data
1 Odpowiedź
+ 8
I found this on Stack Overflow:
y = {}
with open("stuff.txt", "r") as infile:
for line in infile:
key, value = line.strip().split(':')
y[key] = (value)
print(y)
https://stackoverflow.com/questions/30020707/JUMP_LINK__&&__python__&&__JUMP_LINK-how-to-convert-lines-in-a-txt-file-to-dictionary-elements