Created
May 11, 2022 12:26
-
-
Save diogojorgebasso/688d79c3e3680afd211331c8cb9893bd to your computer and use it in GitHub Desktop.
How to invert a list in python?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lista_inicial = [1,2,3,4,5] #input of the list | |
def inversion_sequency(lista): | |
n = len(lista)-1 | |
for j in range(0,n//2+1): | |
print(j) | |
lista[j], lista[n-j] = lista[n-j], lista[j] | |
return lista | |
print(inversion_sequency(lista_inicial)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment