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```
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.