Skip to content

#04 - Python #8310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions Roadmap/03 - ESTRUCTURAS DE DATOS/python/yah1r404.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
'''
ESTRUCTURAS DE DATOS
'''

# LISTAS

my_ice_cream = ["coconut", "vanilla", "chocolate", "oreo"]
print(my_ice_cream)
my_ice_cream.append("cookies and cream")
my_ice_cream.append("cookies and cream") # INSERCIÓN
print(my_ice_cream)
my_ice_cream.remove("coconut") # ELIMINACIÓN
print(my_ice_cream)
print(my_ice_cream[1]) # ACCESO
my_ice_cream[1] = "strawberry" # ACTUALIZACIÓN
print(my_ice_cream)
my_ice_cream.sort() # ORDENACIÓN
print(my_ice_cream)
print(type(my_ice_cream))

# TUPLAS

my_tupla = ("Yahir", "yah1r404", "Sulu", "22")
print(my_tupla[1])
print(my_tupla[3])
my_tupla = tuple(sorted(my_tupla))
print(my_tupla)
print(type(my_tupla))

# SETS

my_set = {"Yahir", "yah1r404", "Sulu", "22"}
print(my_set)
my_set.add("[email protected]")
my_set.add("[email protected]") # INSERCIÓN
print(my_set)
my_set.remove("Sulu") # ELIMINACIÓN
print(my_set)
my_set = set(sorted(my_set))
print(my_set)
print(type(my_set))

# DICCIONARIO

my_dict : dict = {
"name" : "Yahir",
"username" : "yah1r404",
"surname" : "Sulu",
"age" : "22"
}
my_dict["email"] = "[email protected]" # INSERCIÓN
print(my_dict)
del my_dict["surname"] # ELIMINACIÓN
print(my_dict["name"]) # ACCESO
my_dict["age"] = "23" # ACTUALIZACIÓN
print(my_dict)
my_dict = dict(sorted(my_dict.items())) # ORDENACIÓN
print(my_dict)
print(type(my_dict))

'''
TAREA EXTRA
'''

def my_agenda():

agenda = {}

while True:

print("")
print("1. BUSCAR CONTACTO")
print("2. INSERTAR CONTACTO")
print("3. ACTUALIZAR CONTACTO")
print("4. ELIMINAR CONTACTO")
print("5. SALIR")

option = input("\nSelecciona una opción: ")

match option:
case "1":
name = input("Introduce el nombre del contacto: ")
if name in agenda:
print(f"El número de teléfono de {name} es {agenda[name]}.")
else:
print(f"El usuario {name} no existe.")
case "2":
name = input("Escribe el nombre del contacto: ")
phone = input("Escribe el número telefónico del contacto: ")
if phone.isdigit() and len(phone) > 0 and len(phone) <= 11:
agenda[name] = phone
else:
print("Debes introducir un número de teléfono con un máximo de 11 dígitos.")
case "3":
name = input("Introduce el nombre del contacto a actualizar: ")
if name in agenda:
phone = input("Escribe el nuevo número telefónico del contacto: ")
if phone.isdigit() and len(phone) > 0 and len(phone) <= 11:
agenda[name] = phone
else:
print("Debes introducir un número de teléfono con un máximo de 11 dígitos.")
else:
print(f"El usuario {name} no existe.")
case "4":
name = input("Introduce el nombre del contacto a eliminar: ")
if name in agenda:
del agenda[name]
else:
print(f"El usuario {name} no existe.")

case "5":
print("Cerrando la agenda")
break
case _:
print("Opción no válida. Elige un número del 1 al 5")









my_agenda()
148 changes: 148 additions & 0 deletions Roadmap/04 - CADENAS DE CARACTERES/python/yah1r404.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
OPERACIONES
"""

text1 = "Hola"
text2 = "Python"

# CONCATENACIÓN

print(text1 + ", " + text2 + "!")

# REPETICIÓN

print(text1 * 5)

# INDEXACIÓN

print(text1[0] + text1[1] + text1[2] + text1[3])

# LONGITUD

print(len(text2))

# SLICING (PORCIÓN)

print(text2[2:6])
print(text2[2:])
print(text2[0:2])
print(text2[:2])

# BÚSQUEDA

print("a" in text1)
print("m" in text1)

# REEMPLAZO

print(text1.replace("o", "a"))

# DIVISIÓN

print(text2.split("t"))

# MAYÚSCULAS Y MINÚSCULAS

print(text1.upper())
print(text2.lower())
print("yahir sulu".title())
print("yahir sulu".capitalize())

# QUITAR ESPACIOS

print(" yahir sulu ".strip())

# BÚSQUEDA AL PRINCIPIO Y AL FINAL

print(text1.startswith("Ho"))
print(text1.startswith("Py"))
print(text1.endswith("la"))
print(text1.endswith("thon"))

name = "Yahir sulu @yahir404."

# BÚSQUEDA DE POSICIÓN

print(name.find("yahir"))
print(name.find("Yahir"))
print(name.find("y"))
print(name.lower().find("y"))

# BÚSQUEDA DE OCURRENCIAS

print(name.lower().count("u"))

# FORMATEO

print("Saludo: {}, Lenguaje: {}!".format(text1, text2))

# INTERPOLACIÓN

print(f"Saludo: {text1}, Lenguaje: {text2}!")

# TRANSFORMACIÓN EN LISTA DE CARÁCTERES

print(list(name))

# TRANSFORMACIÓN DE LISTA EN CADENA

lista1 = [text1, ", ", text2, "!"]
print("-".join(lista1))

# TRANSFORMACIÓN NUMÉRICA

num = "12345"
num = int(num)
print(num)

num1 = "12345.54321"
num1 = float(num1)
print(num1)


# COMPROBACIONES VARIAS

print(text1.isalnum())
print(text1.isalpha())
print(text1.isnumeric())

"""
EXTRA TASK
"""

def analizar_palabras(palabra1, palabra2):

# Palíndromo: se lee igual al derecho y al revés
print(f"{palabra1} es palíndromo:", palabra1 == palabra1[::-1])
print(f"{palabra2} es palíndromo:", palabra2 == palabra2[::-1])

# Anagrama: tienen las mismas letras, orden diferente
print("Son anagramas:", sorted(palabra1) == sorted(palabra2))

def isogram(word: str) -> bool:
# Creamos un diccionario para contar las apariciones de cada letra
word_dict = dict()

for character in word:
word_dict[character] = word_dict.get(character, 0) + 1

# Obtenemos la lista de cuántas veces aparece cada letra
values = list(word_dict.values())

# Tomamos el valor de repetición de la primera letra
isogram_len = values[0]
isogram = True

# Comparamos todas las repeticiones con la primera
for word_count in values:
if word_count != isogram_len:
isogram = False
break

return isogram
# Ejemplos:
print("¿'aabbcc' es isograma?", isogram("aabbcc")) # True
print("¿'aabc' es isograma?", isogram("aabc")) # False
print("¿'abab' es isograma?", isogram("abab")) # True

analizar_palabras("amor", "roma")