¡Te damos la bienvenida a este reto!
Empezando con Python desde 0
Día 1
Variables, funciones y sintaxis básica
Tipos de datos: Numbers, Strings y Diccionarios
Playground - Retorna el tipo
Día 2
Operadores
Playground - Calcula la propina
Día 3
Condicionales
Playground - Averigua si un año es bisiesto
Ciclos
Playground - Dibuja un triangulo usando bucles
Día 4
Listas
Encuentra a los gatitos más famosos
Diccionarios
Obtén el promedio de los estudiantes
Tuplas
Obten la información de los paquetes
Día 5
Calcula la cantidad de letras en una oración
Encuentra el mayor palíndromo
Día 6
Sets
Encuentre la intersección de conjuntos
Día 7
List comprehension
Encuentra palabras con dos vocales
Dictionary Comprehension
Calcula la longitud de las palabras
Día 8
Funciones Lambda
Filtra mensajes de un user específico
Higher order functions
Crea tu propio método map
Día 9
Manejo de Errores y excepciones
Maneja correctamente los errores
Maneja las excepciones
Día 10
Playground - Crea un task manager usando closures
Día 11
Lectura de archivos de texto y CSV
Día 12
Programación orientada a objetos
Crea un auto usando clases
Día 13
Abstracción en Python
Playground - Crea un sistema de carrito de compras
Encapsulamiento en Python
Playground - Encapsula datos de los usuarios
Día 14
Herencia en Python
Playground - Jerarquía de animales usando herencia
Día 15
Polimorfismo en Python
Playground - Implementa un sistema de pagos
Día 16
Estructuras de datos en Python
Playground - Crea tu propia lista en python
Hash tables en Python
Playground - Implementación de una HashTable para Contactos
Día 17
Maps en Python
Playground - Crea un task manager con Maps
Día 18
Singly Linked List en Python
Playground - Implementación de una singly linked list
Día 19
Stacks en Python
Playground - Implementación de un stack
Día 20
Queues en Python
Playground - Implementación de una queue
Día 21
¡Lo lograste!
No tienes acceso a esta clase
¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera
LeoCode0
Aportes 20
Preguntas 0
Mi aporte
class ContactList:
def __init__(self, size):
self.size = size
self.contact_list = [[] for _ in range(self.size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
# print(index)
self.contact_list[index].append((name, phone))
def get(self, name):
index = self.hash(name)
for key, value in self.contact_list[index]:
if key == name:
return value
return None
def retrieveAll(self):
# return self.contact_list
all_values = []
for contact in self.contact_list:
for key, value in contact:
all_values.append(list((key, value)))
return all_values
def delete(self, name):
index = self.hash(name)
for key, value in self.contact_list[index]:
if key == name:
del self.contact_list[index]
return None
Mi aporte:
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
class ContactList:
def __init__(self, size):
# Tu código aquí 👇
self.size = size
self.buckets = [[] for _ in range(size)]
pass
def hash(self, key):
# Tu código aquí 👇
return hash(key) % self.size
pass
def insert(self, name, phone):
# Tu código aquí 👇
index = self.hash(name)
self.buckets[index].append([name, phone])
pass
def get(self, name):
# Tu código aquí 👇
index = self.hash(name)
for n, p in self.buckets[index]:
if n == name:
return p
return None
pass
def retrieveAll(self):
# Tu código aquí 👇
contacts = []
for bucket in self.buckets:
if isinstance(bucket, list):
contacts.extend(bucket)
else:
contacts.append(bucket)
return contacts
pass
def delete(self, name):
# Tu código aquí 👇
index = self.hash(name)
for i, (n, p) in enumerate(self.buckets[index]):
if n == name:
del self.buckets[index][i]
return
pass```
Mi solución al reto:
class ContactList:
def __init__(self, size):
self.size = size
self.buckets = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
self.buckets[index].append([name,phone])
pass
def get(self, name):
index = self.hash(name)
for k, v in self.buckets[index]:
if k == name:
return v
return None
def retrieveAll(self):
result = []
for b in self.buckets:
if isinstance(b, list) :
result.extend(b)
else:
result.append(b)
return result
def delete(self, name):
index = self.hash(name)
for b, (k, v) in enumerate(self.buckets[index]):
if k == name:
del self.buckets[index][b]
return
.
.
.
.
.
.
.
.
.
.
Mi código:
class ContactList:
def __init__(self, size):
self.size = size
self.buckets = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
self.buckets[index].append((name, phone))
def get(self, name):
index = self.hash(name)
return next((phone for k, phone in self.buckets[index] if k == name), None)
def retrieveAll(self):
return [[key, value] for bucket in self.buckets for key, value in bucket]
def delete(self, name):
index = self.hash(name)
self.buckets[index] = [(k, v) for k, v in self.buckets[index] if k != name]
class ContactList:
def __init__(self, size):
self.size = size
self.buckets = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
if self.get(name) is None:
return self.buckets[index].append((name, phone))
self.delete(name)
self.insert(name, phone)
def get(self, name):
index = self.hash(name)
for k, v in self.buckets[index]:
if k == name:
return v
return None
def retrieveAll(self):
all_values = []
for bucket in self.buckets:
for name, phone in bucket:
all_values.append([name, phone])
return all_values
def delete(self, name):
index = self.hash(name)
for i, (k, v) in enumerate(self.buckets[index]):
if k == name:
del self.buckets[index][i]
.
.
.
.
.
.
.
.
.
.
.
Solución 😄…
.
.
.
.
.
class ContactList:
def __init__(self, size):
self.size = size
self.buckets = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
self.buckets[index].append((name, phone))
def get(self, name):
index = self.hash(name)
for k, v in self.buckets[index]:
if k == name:
return v
return None
def retrieveAll(self):
all_values = []
for bucket in self.buckets:
for name, phone in bucket:
all_values.append([name, phone])
return all_values
def delete(self, name):
index = self.hash(name)
for i, (k, v) in enumerate(self.buckets[index]):
if k == name:
del self.buckets[index][i]
return
return None
class ContactList:
def __init__(self, size):
self.size = size
self.contacts = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
self.contacts[index].append((name, phone))
def get(self, name):
index = self.hash(name)
for key, value in self.contacts[index]:
if key == name:
return value
return None
def retrieveAll(self):
all_values = []
for contact in self.contacts:
for key, value in contact:
all_values.append([key, value])
return all_values
def delete(self, name):
index = self.hash(name)
for i, (key, value) in enumerate(self.contacts[index]):
if key == name:
del self.contacts[index][i]
return
class ContactList:
def __init__(self, size):
self.buckets = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % len(self.buckets)
def insert(self, name, phone):
index = self.hash(name)
self.buckets[index].append((name, phone))
def get(self, name):
index = self.hash(name)
for contact in self.buckets[index]:
if contact[0] == name:
return contact[1]
def retrieveAll(self):
elements = []
for bucket in self.buckets:
for contact in bucket:
elements.append(list(contact))
return elements
def delete(self, name):
index = self.hash(name)
for contact in self.buckets[index]:
if contact[0] == name:
self.buckets[index].remove(contact)
class ContactList:
def __init__(self, size):
self.size = size
self.buckets = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
index = self.hash(name)
self.buckets[index].append((name, phone))
def get(self, name):
index = self.hash(name)
for key, value in self.buckets[index]:
if key == name:
return value
return None
def retrieveAll(self):
all_values = []
for bucket in self.buckets:
for name, phone in bucket:
all_values.append([name, phone])
return all_values
def delete(self, name):
index = self.hash(name)
for i, (k, v) in enumerate(self.buckets[index]):
if k == name:
del self.buckets[index][i]
return
return None
test_insert_new_contact
test_insert_multiple_contacts_same_index
test_get_phone_number_of_contact
test_return_null_if_contact_not_found
test_return_empty_array_if_no_contacts
test_return_array_with_all_contacts
test_delete_contact_from_hash_table
test_return_null_if_contact_not_found_when_deleting
¡Felicidades, todas las pruebas pasaron!
contactList = ContactList(10)
contactList.insert("Mr michi", "123-456-7890")
print(contactList.retrieveAll()) # Output: [["Mr michi", "123-456-7890"]]
phone_number = contactList.get("Mr michi")
print(phone_number) # Output: "123-456-7890"
result = contactList.delete("Mr michi")
print(result) # Output: True
phone_number = contactList.get("Mr michi")
print(phone_number) # Output: None
mi solución:
+
+
+
+
+
+
+
+
+
class ContactList:
def __init__(self, size):
# Tu código aquí 👇
self.size = size
self.buckets = [[] for _ in range(size)]
def hash(self, key):
# Tu código aquí 👇
return hash(key) % self.size
def insert(self, name, phone):
# Tu código aquí 👇
index = self.hash(name)
self.buckets[index].append((name, phone))
def get(self, name):
# Tu código aquí 👇
index = self.hash(name)
for k, v in self.buckets[index]:
if k == name:
return v
return None
def retrieveAll(self):
# Tu código aquí 👇
all_values = []
for bucket in self.buckets:
for key, value in bucket:
all_values.append([key,value])
return all_values
def delete(self, name):
index =self.hash(name)
for i,(k,v) in enumerate(self.buckets[index]):
if k == name:
del self.buckets[index][i]
return
o
o
o
o
o
o
class ContactList:
def __init__(self, size):
self.size = size
self.lista_fija = [[] for _ in range(size)]
def hash(self, key):
return hash(key) % self.size
def insert(self, name, phone):
key = name
index = self.hash(key)
self.lista_fija[index].append(key)
self.lista_fija[index].append(phone)
def get(self, name):
key = name
index = self.hash(key)
if len(self.lista_fija[index]) > 0:
return self.lista_fija[index][1]
else:
return None
def retrieveAll(self):
salida = [elemento for elemento in self.lista_fija if len(elemento) > 0]
return salida
def delete(self, name):
key = name
index = self.hash(key)
if len(self.lista_fija[index]) > 0:
self.lista_fija[index].pop(1)
self.lista_fija[index].pop(0)
return name
else:
return None
def devuelvaTodos(self):
return self.lista_fija
.
.
.
.
.
.
.
.
.
.
class ContactList:
def __init__(self, size):
self._contacts = [[] for _ in range(size)]
self._size = size
def _hash(self, key):
total = 0
for char in key:
total += ord(char)
return total % self._size
def insert(self, name, phone):
index = self._hash(name)
if self._contacts[index] is None:
self._contacts[index] = []
for i, contact in enumerate(self._contacts[index]):
if contact[0] == name:
self._contacts[index][i] = [name, phone]
return
self._contacts[index].append([name, phone])
def get(self, name):
index = self._hash(name)
if self._contacts[index] is not None:
for contact in self._contacts[index]:
if contact[0] == name:
return contact[1]
return None
def retrieveAll(self):
all_contacts = []
for bucket in self._contacts:
if bucket is not None:
all_contacts.extend(bucket)
return all_contacts
def delete(self, name):
index = self._hash(name)
if self._contacts[index] is not None:
for i, contact in enumerate(self._contacts[index]):
if contact[0] == name:
del self._contacts[index][i]
return
return None
SPOILER
.
.
.
.
.
.
.
…
.
.
.
class ContactList:
def __init__(self, size):
# Tu código aquí 👇
self.size = size
self.contactList = [[] for _ in range(size)]
pass
def hash(self, key):
# Tu código aquí 👇
return hash(key) % self.size
pass
def insert(self, name, phone):
# Tu código aquí 👇
index = self.hash(name)
self.contactList[index].append((name, phone))
pass
def get(self, name):
# Tu código aquí 👇
index = self.hash(name)
for k, v in self.contactList[index]:
if k == name:
return v
return None
pass
def retrieveAll(self):
# Tu código aquí 👇
all_values = []
for contact in self.contactList:
for key, value in contact:
all_values.append([key, value])
all_values.reverse()
return all_values
pass
def delete(self, name):
# Tu código aquí 👇
index = self.hash(name)
for i, (k, v) in enumerate(self.contactList[index]):
if k == name:
del self.contactList[index][i]
return
pass
contactList = ContactList(10)
contactList.insert("Mr michi", "123-456-7890")
print(contactList.retrieveAll())
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?