-
-
Save parzibyte/b8d32e24c750c4fe9aafaef235d8ca84 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 obtener_mediana(arreglo): | |
# Primero lo ordenamos. Puedes hacerlo manualmente o con métodos del lenguaje: | |
# https://parzibyte.me/blog/2020/09/25/ordenar-listas-python/ | |
arreglo.sort() | |
# Obtener longitud | |
longitud = len(arreglo) | |
mitad = int(longitud / 2) | |
# Si la longitud es par, promediar elementos centrales | |
if longitud % 2 == 0: | |
mediana = (arreglo[mitad - 1]+arreglo[mitad]) / 2 | |
else: | |
# Si no, es la del centro | |
mediana = arreglo[mitad] | |
return mediana |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment