Script that receives a list of integers, sorts and removes duplicates

-3

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)
    
asked by anonymous 29.06.2018 / 19:32

1 answer

1

I think it's self-explanatory, the set() function removes duplicates and the sorted() function sorts lexicographically < a> an iterable:

def remove_repetidos(lista):
  return sorted(set(lista))
    
30.06.2018 / 07:02