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
CodePudding user response:
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)
CodePudding user response:
Because it is no list, what you probably would like to do is self.songlist.pop(x).
CodePudding user response:
You should remove an item from the list directly with list.pop:
def delsong(self):
for i in enumerate(self.songlist):
# This prints the (index, value) pair as a tuple, is that what you intended?
print(i)
print("which song you will delete: ")
self.songlist.pop(int(input("")))
Note that you provide no way for the user to cancel, except sending an interrupt or providing an invalid index, and that negative indices are valid but counting backwards. For example, if the user types -1 it will remove the last song in the list.
