I'm doing python
course and I'm trying to solve the following exercise:
Exercise 1 - Removing repeated elements
Write the remove_repetitions function that receives a list of integers as a parameter, checks to see if such a list has repeated elements, and removes them. The function should return a list corresponding to the first list, without repeated elements. The returned list must be sorted.
Tip: You can use lista.sort()
or sorted(lista)
. What's the difference?
I gave my code and scored zero, I do not understand where I'm going wrong. Following:
def remove_repetidos (lista):
lista2 = set(lista)
lista = list(lista2)
lista.sort()
print (lista)
lista = []
while True:
x = int(input('Numero: '))
if x == 0:
break
lista.append(x)
remove_repetidos(lista)