I am new at Python and I dont know what would be the best way to approuch this problem: I want to save nested lists in python as strings in a text file and then be able to load the information from the text file.
I would like to do something like that keeping in mind that the list and the dic are two random examples, the solution needs to be general.
This is how I would save it:
list = ["29", "24", "33", "34", ["25", "2" ,"3", "14", "79"], ["0", "26"]]
dict = {'A' : ["25", "2" ,"3", "14", "79"], 'B' : ["0", "26"], 'C' : ["0", "26", "33"]}
f = open("doc.txt","w")
f.write(str(dict)+"\n")
f.write(str(list))
f.close()
Then I would like to read the lines of the text file and load back the information they store like that but with the correct data type.
f = open("doc.txt","r")
content = f.read()
dic, list = content.split("\n")
f.close()