-3
I’m taking a course in python
and I’m trying to solve the following exercise:
Exercise 1 - Removing repeated elements
Write the remove_repeated function that takes as a parameter a list of integer numbers, checks whether such a list has repeated elements and removes them. The function should return a list corresponding to the first list, without repeating elements. The returned list should be sorted.
Tip: You can use lista.sort()
or sorted(lista)
. What’s the difference?
I posted my code and I got a zero grade, I don’t understand where I’m going wrong. Follow:
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)
Tip: see here how to format the code in the posts, and click [Edit] to do it in your question.
– hkotsubo
Thanks buddy, I already saved here
– Leandro Sargi
In the statement he gives examples of how the input and output should be?
– Daniel Reis
Possible duplicate of Call list in function in python 3
– Woss
You are doing nothing with the result of the function
remove_repetidos
. You didn’t tell us what website you’re doing the exercise on, but you may have to print the result or define a specific function so that it recognizes the answers. Read the instructions.– Pedro von Hertwig Batista