辞書に変更を保存するにはどうすればよいですか?まだあなたがあなたのPythonのファイルを開くときは、データを読み込み、ファイルにデータを保存するためにJSONを使用することができPythonプログラムが自分自身に加えた変更を保存するようにする
words = {
"orange": "naranja",
"hello": "hola",
"bye": "adiós",
"red": "rojo",
"blue": "azul",
"yellow": "amarillo",
"purple": "púrpura",
"green": "verde",
"white": "blanco",
"black": "negro",
"Ethan": "Yeet"
}
while 1 == 1:
tt = input("What would you like to translate? (Only write in lowercase and type EXIT to quit) ")
if str(tt) in words:
print(tt + " is " + words.get(tt, "Not in dictionary"))
elif str(tt) == "EXIT":
break
else:
atd = input("Would you like to add " + str(tt) + " to our dictionary? Y/N ")
if atd == "Y" or atd == "y":
d = input("What does it translate to? ")
d = str(d)
tt = str(tt)
words.update({tt: d})
print(tt + " is "+ words.get(tt, "What"))
continue
elif str(atd) == "EXIT":
break
else:
continue
あなたは何を意味するか、 "辞書に変更を保存します?"技術的には、すでに 'words.update({tt:d})'でそれをやっています。 –
@ JohnPerry質問のように聞こえるのは、これらの変更をファイルに永続させることです。 –
@DavidZそれは私の考えでもありましたが、その場合には彼は読み書きが必要です。 –