-
-
Save parzibyte/d3cd0ef3cd523ad3abbb9d54498f1af5 to your computer and use it in GitHub Desktop.
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
def mezclar_lista(lista_original): | |
# Crear una copia, ya que no deberíamos modificar la original | |
# https://parzibyte.me/blog/2020/05/31/python-clonar-lista-eliminar-referencia/ | |
lista = lista_original[:] | |
# Ciclo for desde 0 hasta la longitud de la lista -1 | |
longitud_lista = len(lista) | |
for i in range(longitud_lista): | |
# Obtener un índice aleatorio | |
# https://parzibyte.me/blog/2019/04/04/generar-numero-aleatorio-rango-python/ | |
indice_aleatorio = random.randint(0, longitud_lista - 1) | |
# Intercambiar | |
temporal = lista[i] | |
lista[i] = lista[indice_aleatorio] | |
lista[indice_aleatorio] = temporal | |
# Regresarla | |
return lista |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment