question regarding .remove( ) function using a for loop [duplicate]

  function, list, loops, python, python-3.x

The output that I am getting is [6,6,6]. I changed the list elements sequence, placing 6 alternatively to any number, for example [4,6,5,6,7,6,8,6,9,6,10,6,11,6], then it removed every element 6 from the list

I want to remove a repeating element in a list regardless of it’s arrangement

my_list = list([6,6,6,6,6,6,6])

for item in my_list:
    my_list.remove(6)

print(my_list)

Source: Python-3x Questions

LEAVE A COMMENT