-
-
Save parzibyte/976eab38d70bb8361ac46e133f98865d 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
""" | |
Longitud de una cadena o lista en Python | |
sin usar la función len ni un ciclo foreach | |
@author parzibyte | |
""" | |
def longitud(valor): | |
contador = 0 | |
while True: | |
try: | |
valor[contador] | |
contador += 1 | |
except IndexError: | |
break | |
return contador | |
# Probar | |
cadena = "Hola" | |
print("Longitud de cadena:", longitud(cadena)) | |
cadena = "" | |
print("Longitud de cadena:", longitud(cadena)) | |
lista = ["Panic in Detroid", "Let me go", "Shattered"] | |
print("Longitud de lista:", longitud(lista)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment