The operations you want are set operations. python has its own data structure called set()
See below:
>>> lista_inicio = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "J", "Q", "K", "A"]
>>> lista_chamada = ["1", "2"]
>>> print(set(lista_inicio) - set(lista_chamada))
{'9', '4', 'A', 'Q', '8', '5', 'K', 'J', '7', '3', '6'}
If you need the result to be a list, use:
print(list(set(lista_inicio) - set(lista_chamada)))
Of course you can assign to a variable
lista_resultado = list(set(lista_inicio) - set(lista_chamada)))
As for the repeated items, the structure of the set
already treats that
>>> lista = [1, 1, 1, 2, 2, 3, 3, 3, 3]
>>> print(set(lista))
{1, 2, 3}
See below briefly how to add items in set()
>>> conjunto = set([1, 2, 3])
>>> print(conjunto)
{1, 2, 3}
>>> conjunto.add(4)
>>> print(conjunto)
{1, 2, 3, 4}
>>> conjunto.add(4)
>>> print(conjunto)
{1, 2, 3, 4}
>>> conjunto.add(1)
>>> print(conjunto)
{1, 2, 3, 4}
Notice that the second 4
and subsequently the second 1
, nay were included.
In time: The response marked as a solution on 07/22/2021 is not performative.
Boot
lista
with a superficial copy oflista_inicio
thuslista = lista_inicio[:]
and eternal forlista_chamada
removing fromlista
its elements andfor e in lista_chamada: lista.remove(e)
see for example: https://ideone.com/CHnaym– Augusto Vasques