Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add values to list without deleting already exsists

so as i have written in title i have problem with 2 things, mainly i want to add values in to a list and dont delete already existing, but i cant figure out how to do it, for now when im writing something everything old gets deleted. My second problem is that i cant make condition to use upper letter T and lower t, can anyone help me? here is the code:

import pickle



    zadania = []
    
    a = input("Do you want to add value? T/N")
    while True:
        if a == 'T':
            zadania.append(str(input('Write what you want to add: ')))
            a = input("Do you want add something else? T/N")
    
        elif a == 'N':
            break
        else:
            while a not in 'TN':
                print("Wrong value")
                a = input("Do you want add something else? T/N")
    
    
    with open('zad', 'wb') as fp:
        pickle.dump(zadania, fp)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

zadania = []

This always starts with an empty list. If you don’t want that, then you should do something different. For example, you could check if the file you wrote before already exists. If it does, load it before getting more items.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading