Reputation: 83
I have
x = 1
list = [1,2,3]
I want to remove the 1 in the list by referencing its value of x,not the index - without using list.remove(x). How is this possible?
Upvotes: 1
Views: 109
Reputation: 6575
Indeed, there is a lot of way to do that.
x = 5
my_list = [1, 2, 3, 5, 6, 9, 4]
del my_list[my_list.index(x)]
or
my_list.pop(my_list.index(x))
Upvotes: 1