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?
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?
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))
list = [1,2,3]
list = [i for i in list if i is not 1]
x