Search code examples
pythonlisttuplesenumerate

Why I can't delete vaules in enumerated list?


I wanna delete these tuples with using remove but I can't. How should I delete values in list?(list like ["a","b,","c"])

def delsong(self):
    value=enumerate(self.songlist)
    for i in value:
        print(i)
    print("which song you will delete: ")

    x=int(input(""))
    value.remove(x)

    pass

Solution

  • value is an iterator, not the list itself. You need to remove the item from self.songlist instead.

    Since you are expecting the user to enter an index number, you need to use self.songlist.pop(x). The remove() method removes an item based on its value (not its index)