Dec-13-2019, 05:39 PM
(Dec-12-2019, 03:19 AM)slackerman73 Wrote: I'm trying to remove an item from the passwords list.
I keep getting Traceback (most recent call last):
passwords.remove(websitetodelete) #This line is where I'm hung up. Trying to remove the websitetodelete from the previous line. I'm sure i'm not referencing the list correctly.
ValueError: list.remove(x): x not in list
Not sure
passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] while True: print("What would you like to do:") print(" 1. Open password file") print(" 2. Lookup a password") print(" 3. Add a password") print(" 4. Save password file") print(" 5. Print the encrypted password list (for testing)") print(" 6. Quit program") print(" 7. Delete a password") print("Please enter a number (1-7)") choice = input() if(choice == '7'): #Delete a password print("Which website do you want to delete?") for keyvalue in passwords: print(keyvalue[0]) #Printing the list of websites for the user to choose from. websitetodelete = input() #Accepting the user's input for the website to remove. passwords.remove(websitetodelete) #This line is where I'm hung up. Trying to remove the websitetodelete from the previous line. I'm sure i'm not referencing the list correctly.
If this is the way that the assignment requires that you do it and you do not understand list reconstruction then you need to find the entry that contains the website using a loop.
You've got everything else right, but you are trying to delete something that doesn't exist in the list. The lists remove function must contain the entire entry, where as you are only trying to remove part.
"yahoo" # This is what you have ["yahoo","XqffoZeo"] # This is what you needHere is the loop that will give you the complete entry
for combo in passwords: # Read each website / password combo in the passwords list if combo[0] == websitetodelete: # If it matches the site the user specified websitetodelete = combo # Update the query to contain the entire combo break # Stop looking because you've found it passwords.remove(websitetodelete) # Now this command will work