3
I’m solving a problem in Python 3, about lists.
Part of my solution involves sorting a list of values float
, I decided to use the method sort
. This method should return the already ordered list in ascending order, but that is not what is happening.
The function I’m writing works more or less like this:
def inverter(lista):
lista_invertida = []
lista = lista.sort()
lista_invertida = lista[::-1]
return lista_invertida
However this was not working, I did a test to check if there was something "broken".
I wrote a print
to show me the list before and after it is ordered.
Before being ordered the list was like this:
34.7, 43.5, 31.1, 40.7, 20.3, 19.9
Soon after the ordering the list was like this:
None, None, None, None, None, None
This broke the function I had written, the interpreter kept trying to invert the list only formed by None
...
I would like to know if there is something wrong, and/or if there is a way to correct that return.
Perfect!!! The
sort(reverse = True)
solved, by still having some things I need to treat.– Leonardo Oliveira