I would like to remove repeated integers from a list and return a new list.
lista = [1, 2, 3, 3, 3, 4, 5, 6, 6, 7, 8]
The result would have to be this:
[1, 2, 3, 4, 5, 6, 7, 8]
I would like to remove repeated integers from a list and return a new list.
lista = [1, 2, 3, 3, 3, 4, 5, 6, 6, 7, 8]
The result would have to be this:
[1, 2, 3, 4, 5, 6, 7, 8]
set
does just this. If you're concerned that the result type is a list
, just do the conversion from set
to that
a = [1, 2, 3, 3, 3, 4, 5, 6, 6, 7, 8]
b = set(a) # Conjunto a partir de 'a', vai remover todos os repetidos
c = list(b) # lista a partir de 'b', vai converter o set numa list
print(a) # [1, 2, 3, 3, 3, 4, 5, 6, 6, 7, 8]
print(b) # {1, 2, 3, 4, 5, 6, 7, 8}
print(c) # [1, 2, 3, 4, 5, 6, 7, 8]