xxxxxxxxxx
dict = {'Python' : '.py', 'C++' : '.cpp', 'Java' : '.java'}
f = open("dict.txt","w")
f.write( str(dict) )
f.close()
xxxxxxxxxx
import json
# Dictionary to be saved
my_dict = {'key1': 'value1', 'key2': 'value2'}
# Open a file for writing
with open('dict.txt', 'w') as f:
# Write the dictionary to the file in JSON format
json.dump(my_dict, f)