Remove repeated integers list in Python

0

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]
    
asked by anonymous 11.01.2018 / 18:41

1 answer

5

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]
    
11.01.2018 / 18:53