The easiest way would be to save it in a file as a json.
# trial code for to do list tdl=list() # Reading from file with open("listentries.txt", "r") as file: tdl = json.loads(file.read()) print(*tdl,sep="\n") while True: choice=input("Do you want to edit the list(y/n):") if choice =="y": print("1. Do you want to add an entry") print("2. Do you want to remove an entry") choice2=input("What do you want to do(1/2):") if choice2 == '1': x=input("Enter new entry:") tdl.append(x) print(*tdl,sep="\n") if choice2 =='2': y=int(input("Enter the number of entry you want to remove:")) z=y-1 tdl.pop(z) print(*tdl,sep="\n") if choice=="n": # Saving to file with open("listentries.txt", "w") as file: file.write(json.dumps(tdl)) break
I modified your code so that every time you start the program the information is loaded from the file and every time you stop the application it is saved into the file.
What do the codelines accomplish:
with open("listentries.txt"), "r") as file: It opens or creates the listentries.txt file in read mode ("r") and returns an file-object with the name file. The with statement ist a so called context manager for a deeper dive take a look here
tdl = json.loads(file.read()): I decided to store your information in JSON-Format which is a standardized way to safe or send data (find more here). So file.read() reads the information from the file and makes it accesible. This is then handed to the json.loads which allows you to convert strings into lists or dictionaries.
with open("listentries.txt", "w") as file: It does the same as above with the difference that it opens the file in order to write into it, thus "w" is handed as a parameter instead of "r"
file.write(json.dumps(tdl)): It does the same as above just in reverse. Now you have a list which you would like to write into a file. So we use json.dumps to convert it to a string in json-format and then write this into the file.
I think this should do it for you