I have just started learning Python and I have created a simple dictionary with a text editor
Spain Spanien
Germany Deutschland
Sweden Schweden
France Frankreich
Greece Griechenland
Italy Italien
The dictionary is called worterbuch.txt. I can read it with a python program called worterbuch.py
woerter={}
fobj = open("woerterbuch.txt", "r")
for line in fobj:
print(line)
fobj.close
This gives the content of the text file as an output. It seems simple enough. Is there a simple way to do the reverse, i.e. create the text file by typing the text in Python and telling the program to create a dictionary from it? What I have tried is
woerter={}
fobj=open("dict.txt", "w")
woerter={"Germany", "Deutschland",
"Italy", "Italien"}
fobj.close()
but this produces just an empty dict.txt file.