list = ['table', 'chair', 'door', 'lamp', 'roof'] # ordinal number 0th, 1st, 2nd, 3rd, 4rth
list_deleted_items = []
while (True):
if choice =="2":
number = input("Please give the ordinal number of the item in the list that you want to delete: ")
list_deleted_items.append(list.seek(int(number) -1) # this adds the item that is to be deleted to the other list
list.remove(list.seek(int(number) -1)) # this deletes the item, the user is expected to give ordinal numbers 1, 2, 3, 4, or 5, therefore "-1" is added
elif choice == "0":
print("The items you removed from your list are:")
print(list_deleted_items)
break
This is my idea of how this could work, I know it does not, but how does it work?
And donât use Python reserved words when naming your objects.
list = ['table', 'chair', 'door', 'lamp', 'roof'] â NO! item_list = ['table', 'chair', 'door', 'lamp', 'roof'] â Would be better.
To add: thereâs other fundamental errors here that youâll fall over, but youâll find them.
To further add:
You donât in fact need any other methods aside from the ones you are using: .append() and .remove(). The items can be located with pure indexing:
My final edit:
Maybe a cleaner way would be to have remove = item_list[number - 1], then remove would hold the name of the item, rather than an index position. That way you could have item_list.remove(remove) and list_deleted_items.append(remove)
Of note: a reasonably good code editor (that recognizes Python) will colorize any reserved words, in a similar way as on this Forum, so that theyâre easy to spot.