The reason I decided to write this list was that when I created a list with no duplicate elements, I used remove () to remove the elements. I misunderstood that using remove () would remove all the specified values.
l = [1, 2, 3, 4, 1]
l.remove(1)
print(l)
#[2, 3, 4, 1]
In this way, you can delete the specified value that appears first. However, with this code, only one can be deleted, so the following behavior will occur.
l = [1, 2, 3, 4, 1, 1]
l.remove(1)
print(l)
#[2, 3, 4, 1, 1]
Therefore, in order to create a unique list, the code should look like this:
l = [3, 4, 3, 2, 5, 4, 3]
l_u = []
for i in l:
if i not in l_u:
l_u.append(i)
#[3, 4, 2, 5]
This allows you to create a unique list of elements.
Referenced site https://www.lifewithpython.com/2013/11/python-remove-duplicates-from-lists.html https://note.nkmk.me/python-list-clear-pop-remove-del/
I will add it because I received a comment. It seems that the following code can be executed faster than the code described above. You can also save the order.
l = [3, 4, 3, 2, 5, 4, 3]
print(sorted(set(l), key=l.index))
#[3, 4, 2, 5]