Use of .seek on a list by the user inputting ordinal number


this time I ask about how to use of .seek

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( -1) # this adds the item that is to be deleted to the other list
           list.remove( -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:")            

This is my idea of how this could work, I know it does not, but how does it work?

Thank you in advance.

Have a look the the list methods here:

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:

list_deleted_items.append(item_list[int(number) - 1])
item_list.remove(item_list[int(number) - 1])

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)

I trust all this is of some help?

1 Like

I am researching it right now. I am very grateful for your knowledge.
So list is reserved, I see. Good to know.

The code works. Thank you again.

1 Like

You are very welcome.

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.