Move one element from a list to the end

Hy! I have problem to solve this problem. Can anyone helps me?? Thanks!

#Write a function that moves all elements of one type to the end of the list.

def move_to_end(lst,el):
lst.append(lst.pop(lst.index(el)))
return lst

print(move_to_end([1, 3, 2, 4, 4, 1], 1))
print(move_to_end([7, 8, 9, 1, 2, 3, 4], 9))
print(move_to_end([“a”, “a”, “a”, “b”], “a”))

for the 3-rd one it doesn’t work. I don’t know how to develop other solution for this problem.
And why for the first and second it works but for the 3-rd one it doesn’t work?

Hey,

I copied the code and for some reason, my editor didn’t recognize your “” in the 3rd list.

I replaced them and the now code works fine.

def move_to_end(lst,el):
    lst.append(lst.pop(lst.index(el)))
    return lst

print(move_to_end([1, 3, 2, 4, 4, 1], 1))
print(move_to_end([7, 8, 9, 1, 2, 3, 4], 9))
print(move_to_end(["a","a","a","b"], "a"))

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.