I have a list like that:
['Alice,Female,1994\n', 'Bob,Male,1995\n', 'Carol,Male,1993\n', 'Felix,Male,1990\n', 'Giacomo,Male,1990\n', 'Irena,Female,1992\n', 'Joe,Male,1995\n', 'Leo,Male,1995\n', 'Marco,Male,1991\n', 'Tania,Female,1992\n', 'Lillo,Male,1994']
Then I want to remove one string just inserted the name (for example "Lillo") then I want to delete it also from a file. I did something like that but it does not work. I insert the name, looks like it check if the name exist but then, when I ask for showing the file, 'Lillo,Male,1994' is still there. Can you help me? Here is my code:
name = input("Insert the name you want to delete: ")
book = "data.txt"
f = open(book,'r')
line = f.readlines()
f.close()
print(line)
for p in range(len(line)):
lineString = line[p].split(',')
if lineString[0] == name:
line.pop(p)
print(line)
USING THIS CODE FROM @ANON IT WORKS. But how to remove it from the file?