Sergio Andrés Bolaños Penagos
EstudianteCamilo Andrés Rodriguez Higuera
EstudianteNicolas Alpargatero
EstudianteZaidibeth Ramos
EstudianteAlejandro Anaya
EstudianteEdgar Alarcón
EstudianteNicolas Alpargatero
EstudianteDiego Cruz
EstudianteFabricio González Guasque
EstudianteVictor Ortiz
EstudianteWaldir Zapata Garcia
EstudianteJosé Miguel Reyes
Estudianteiecgerman .
EstudianteFernando Jesús Núñez Valdez
EstudianteLinda Atenea Mejía Usme
EstudianteHarold Zurita Simon
EstudianteBrayan Estiben Rodallega Saavedra
EstudianteGonzalo Gutiérrez Castillo
EstudianteJhon Freddy Tavera Blandon
EstudianteNicolas Alpargatero
EstudianteJuan Camilo Aristizabal Carvajal
EstudianteDavid Hereira
EstudianteJulio Cardenas
EstudianteEs un diccionario, no una lista, que confundido me pusieron con eso
Me han gustado las practicas del reto, estan chevveres para practicar, y recomendaria un curso de poo para python unicamente
class MyList: def __init__(self): self.data: dict = {} self.length: int = 0 def append(self, item): self.data[self.length] = item self.length +=1 def pop(self): self.length -=1 return self.data.pop(max(self.data.keys())) def shift(self): self.length -=1 first = self.data[0] self.data = {key-1: value for key, value in self.data.items() if key != 0} return first def unshift(self, item): self.length += 1 self.data = {key+1: value for key, value in self.data.items()} self.data[0] = item def map(self, func): map_list = MyList() for idx in range(len(self.data)): map_list.append(func(self.data[idx])) return map_list def filter(self, func): map_list = MyList() for idx in range(len(self.data)): if func(self.data[idx]): map_list.append(self.data[idx]) return map_list def join(self, character=","): result = "" for idx in range(len(self.data)): if result == "": result += str(self.data[idx]) else: result += character + str( self.data[idx]) return result
Pues es que según ellos es este: https://platzi.com/cursos/python-practico/ . Pero sinceramente no está enfocado a OOP. si lo utilizan super implementado pero no es explicado.
ESTE es el curso que estas buscando https://platzi.com/clases/1474-oop/16669-por-que-aprender-programacion-orientada-a-objetos/
Ese curso lo acaban de sacar de las listas de busqueda aqui en platzi, es de POO enfocado en python
De resto, te dejo algunos links de platzi para que revises
https://platzi.com/cursos/algoritmos-python/ https://platzi.com/clases/1378-python-practico/14179-programacion-orientada-a-objetos-en-python/ https://platzi.com/clases/1104-python-2019/7113-clas-6/ https://platzi.com/clases/2211-historia-programacion/35076-programacion-orientada-a-objetos/ https://platzi.com/tutoriales/1775-algoritmos-python/6805-notas-sobre-programacion-orientada-a-objetos-en-python/ https://platzi.com/tutoriales/1474-oop/9009-apuntes-del-curso-de-programacion-orientada-a-objetos/ https://platzi.com/tutoriales/1474-oop/9422-notas-del-curso-de-programacion-orientada-a-objetos-con-enfoque-a-python/ https://platzi.com/tutoriales/1474-oop/8828-herencia-con-python/ https://platzi.com/tutoriales/1474-oop/9451-explicacion-detallada-de-cada-capitulo-del-curso/
🛡️🛡️Escudo anti-spoilers🛡️🛡️
Mi solución al reto: En este reto, no termine de leer el ultimo parrafo de las indicaciones para completarlo, asi que cuando ya tenia el código terminado sin usar metodos built-in de las listas, me di cuenta que mi propiedad se tenia que llamar 'data' y tenia que ser un diccionario... Me dio pereza rehacerlo y mejor use lo aprendido y engañe a las pruebas usando getters y setters, y converti mi lista a un dict.
class MyList: def __init__(self): self.list = [] self.length = 0 def append(self, item): self.list += [item] self.length += 1 def pop(self): poped = self.list[-1] self.list = self.list[:-1] self.length -= 1 return poped def shift(self): shifted = self.list[0] self.list = self.list[1:] self.length -= 1 return shifted def unshift(self, item): self.list = [item] + self.list self.length += 1 def map(self, func): newList = MyList() newList.list = [ func(e) for e in self.list ] newList.length = len(newList.data) return newList def filter(self, func): filteredList = MyList() filteredList.list = [ e for e in self.list if func(e) ] filteredList.length = len(filteredList.data) return filteredList def join(self, character=','): newString = "" for e in self.list: newString = newString + str(e) + str(character) return newString[:-1] @property def data(self): return { i:v for (i,v) in enumerate(self.list)} @data.setter def data(self,v): self.list = v
Saludos. No comprendo, si estamos trabajando con listas, porque las respuestas debe ser diccionarios?
se confundieron de hecho hasta en los ejemplos colocando myArray, cuando ni existe.
Mi respuesta al reto:
class MyList: def __init__(self): # Tu código aquí 👇 self.data = dict() self.length = int() def append(self, item): # Tu código aquí 👇 """ append(item): agrega un elemento item al final de la lista y aumenta la longitud (length). """ self.data[self.length] = item self.length += 1 def pop(self): # Tu código aquí 👇 """ pop(): elimina el último elemento de la lista y lo retorna, disminuyendo también la longitud (length). """ if self.length == 0: raise IndexError("pop from empty list") newDict = dict() for key, value in self.data.items(): if key == self.length -1: removedValue = value break newDict[key] = value self.data = newDict self.length -= 1 return removedValue def shift(self): # Tu código aquí 👇 """ shift(): elimina el primer elemento de la lista y lo retorna, disminuyendo la longitud (length). """ if self.length == 0: raise IndexError("pop from empty list") llave = 0 newDict = dict() for key, value in self.data.items(): if key == 0: removedValue = value continue newDict[llave] = value llave += 1 self.data = newDict self.length -= 1 return removedValue def unshift(self, item): # Tu código aquí 👇 """ unshift(item): agrega un elemento item al inicio de la lista y aumenta la longitud (length). """ if self.length == 0: raise IndexError("pop from empty list") newDict = dict() newDict[0] = item for key, value in self.data.items(): newDict[key+1] = value self.data = newDict self.length += 1 def map(self, func): # Tu código aquí 👇 """ map(func): itera sobre cada elemento de nuestra estructura aplicando la función func a cada uno de ellos y devuelve una nueva lista (que será una instancia de MyList). """ mapped_list = MyList() for key, value in self.data.items(): mapped_list.append(func(value)) return mapped_list def filter(self, func): # Tu código aquí 👇 """ filter(func): itera sobre cada elemento de nuestra estructura filtrándolos según lo que indique la función func y devuelve una lista con los elementos filtrados (también una instancia de MyList). """ filtered_list = MyList() for key, value in self.data.items(): if func(value): filtered_list.append(value) return filtered_list def join(self, character=","): # Tu código aquí 👇 """ join(character): concatena todos los elementos de nuestra estructura de datos en un string, separándolos por el carácter indicado (character). Si no se proporciona un carácter, el separador por defecto será una coma ",". """ item = str() for key, value in self.data.items(): if self.length-1 != key: item += str(value)+character else: item += str(value) return item
Mi aporte, sin usar métodos nativos de las listas . . . . . . . . . . . . . . . . . . . . .
class MyList: def __init__(self): # Tu código aquí 👇 self.data = {} self.length = 0 pass def append(self, item): # Tu código aquí 👇 self.data[self.length] = item self.length += 1 pass def pop(self): # Tu código aquí 👇 rData = self.data[self.length - 1] del self.data[self.length - 1] self.length -= 1 return rData pass def shift(self): # Tu código aquí 👇 rData = self.data[0] for i in range(0, self.length - 1): self.data[i] = self.data[i + 1] del self.data[self.length - 1] self.length -= 1 return rData pass def unshift(self, item): # Tu código aquí 👇 if item != None: for i in range(self.length, 0, -1): self.data[i] = self.data[i - 1] self.data[0] = item self.length += 1 return self.length pass def map(self, func): # Tu código aquí 👇 rMap = MyList() for i in range(0, self.length): rMap.append(func(self.data[i])) return rMap pass def filter(self, func): # Tu código aquí 👇 rFilter = MyList() for i in range(0, self.length): if func(self.data[i]): rFilter.append(self.data[i]) return rFilter pass def join(self, character = ','): # Tu código aquí 👇 rJoin = '' for i in range(0, self.length): rJoin += str(self.data[i]) if i < self.length - 1: rJoin += character return rJoin pass
Mi código:
class MyList: def __init__(self): self.data = {} # Será un Diccionario, no una lista self.length = 0 def append(self, item): self.data[self.length] = item self.length += 1 def pop(self): if self.length > 0: self.length -= 1 return self.data.pop(self.length, None) else: return None def shift(self): if self.length > 0: item = self.data[0] temp_data = {} for i in range(1, self.length): temp_data[i - 1] = self.data[i] self.data = temp_data self.length -= 1 return item else: return None def unshift(self, item): temp_data = {} temp_data[0] = item for i in range(self.length): temp_data[i + 1] = self.data[i] self.data = temp_data self.length += 1 def map(self, func): new_list = MyList() for i in range(self.length): new_list.append(func(self.data[i])) return new_list def filter(self, func): new_list = MyList() for i in range(self.length): if func(self.data[i]): new_list.append(self.data[i]) return new_list def join(self, character=","): if self.length == 0: return "" joined_string = str(self.data[0]) for i in range(1, self.length): joined_string += character + str(self.data[i]) return joined_string
Vaya hasta que nos ponen algo ya mas fácil y tranqui
Mi Solución: . . . . . . . . . . . . . . . .
class MyList: def __init__(self): self.data = {} self.length = 0 def _reasignar_keys(self): """Re-ordena las keys para que inicien en 0 y terminen en length""" new_data = {} index = 0 # If insert item at 0 if -1 in self.data: new_data[0] = self.data.pop(-1) index = 1 # if remove item at 0 for key in self.data: new_data[index] = self.data[key] index += 1 self.data = new_data def append(self, item): """Agrega un elemento item al final de la lista""" self.data[self.length] = item self.length += 1 def pop(self): """Elimina el último elemento de la lista y lo retorna""" val = self.data.pop(self.length - 1) self.length -= 1 return val def shift(self): """Elimina el primer elemento de la lista y lo retorna""" val = self.data.pop(0) self.length -= 1 self._reasignar_keys() return val def unshift(self, item): """Agrega un elemento item al inicio de la lista""" self.data[-1] = item self.length += 1 self._reasignar_keys() def map(self, func): """ itera sobre cada elemento de nuestra estructura aplicando la función func a cada uno de ellos y devuelve una nueva lista (que será una instancia de MyList""" new_list = MyList() for key in self.data: new_list.append(func(self.data[key])) return new_list def filter(self, func): """ itera sobre cada elemento de nuestra estructura filtrándolos según lo que indique la función func y devuelve una lista con los elementos filtrados (también una instancia de MyList).""" new_list = MyList() for key in self.data: if func(self.data[key]): new_list.append(self.data[key]) return new_list def join(self, character = ','): """concatena todos los elementos de nuestra estructura de datos en un string, separándolos por el carácter indicado (character). Si no se proporciona un carácter, el separador por defecto será una coma ",".""" string = '' for item in self.data.values(): string += str(item) + character return string[:-len(character)]
class MyList: def __init__(self): self.data = {} self.length = 0 def append(self, item): self.data[self.length] = item self.length += 1 def pop(self): self.length -= 1 to_return = self.data[self.length] del self.data[self.length] return to_return def shift(self): item_index = 0 to_return = self.data[item_index] while item_index < self.length - 1: self.data[item_index] = self.data[item_index + 1] item_index += 1 self.pop() return to_return def unshift(self, item): item_index = self.length while item_index > 0: self.data[item_index] = self.data[item_index - 1] item_index -= 1 self.data[item_index] = item self.length += 1 def map(self, func): data_with_map = MyList() item_index = 0 while item_index < self.length: data_with_map.append(func(self.data[item_index])) item_index += 1 return data_with_map def filter(self, func): data_with_filter = MyList() item_index = 0 while item_index < self.length: if func(self.data[item_index]): data_with_filter.append(self.data[item_index]) item_index += 1 return data_with_filter def join(self, character=","): item_index = 0 string = "" while item_index < self.length - 1: string += f"{self.data[item_index]}{character}" item_index += 1 return string + f"{self.data[item_index]}"
Solución 😄… .
class MyList: def __init__(self): self.data = {} self.length = 0 def append(self, item): self.data[self.length] = item self.length += 1 def pop(self): self.length -= 1 return self.data.pop(self.length) def shift(self): self.length -= 1 self.data = { key-1: self.data[key] for key in self.data } return self.data.pop(-1) def unshift(self, item): self.length += 1 self.data = { key+1: self.data[key] for key in self.data } self.data = {**{0:item}, **self.data} def map(self, func): newList = MyList() newList.data = { key: func(self.data[key]) for key in self.data } newList.length = len(newList.data) return newList def filter(self, func): newList = MyList() index = 0 for key in self.data: if func(self.data[key]): newList.data[index] = self.data[key] index += 1 newList.length = len(newList.data) return newList def join(self, character=","): return character.join([ str(value) for value in self.data.values() ])
class MyList: def __init__(self): self.data = {} self.length = 0 def append(self, item): self.data[self.length] = item self.length += 1 def pop(self): element = None if self.data != {}: element = self.data[self.length - 1] del self.data[self.length - 1] self.length -= 1 return element def shift(self): element = None if self.data != {}: element = self.data[0] del self.data[0] self.data = {item - 1: value for item, value in self.data.items()} self.length -= 1 return element def unshift(self, item): if self.data != {}: aux = {0: item} for item, value in self.data.items(): aux[item + 1] = value self.data = aux self.length += 1 def map(self, func): payload = MyList.__new__(MyList) payload.data = {} payload.length = self.length for item, value in self.data.items(): payload.data[item] = func(value) return payload if payload else None def filter(self, func): payload = MyList.__new__(MyList) payload.data = {} payload.length = 0 for item, value in self.data.items(): if func(value): payload.data[payload.length] = value payload.length += 1 return payload if payload else None def join(self, character = ','): string = '' if self.data != {}: for key, value in self.data.items(): if key == self.length-1: string += f'{value}' else: string += f'{value}{character}' return string
class MyList: def __init__(self): self.data = {} self.length:int = 0 def append(self, item): if self.length == 0: self.data[0]=item self.length = 1 else: self.data[self.length]=item self.length += 1 def pop(self): if self.length>0: last_item=self.data[self.length-1] del self.data[self.length-1] self.length-=1 return last_item else: return def shift(self): if self.length>0: first_item=self.data[0] del self.data[0] self.data={index-1:self.data[index] for index in self.data} self.length-=1 return first_item else: return def unshift(self, item): if self.length>0: self.data={index+1:self.data[index] for index in self.data} self.data[0]=item self.length+=1 else: return def map(self, func): if self.length>0: new_list=MyList() for item in self.data: new_list.append(func(self.data[item])) return new_list else: return def filter(self, func): if self.length>0: new_list = MyList() for index in range(self.length): if func(self.data[index]): new_list.append(self.data[index]) return new_list else: return def join(self, character=","): if self.length>0: new_string=f"{self.data[0]}" for index in range(self.length-1): new_string+=f"{character}{self.data[index+1]}" return new_string else: return myList = MyList() myList.append("Platzinauta") myList.unshift("Hola!") myList.append("Como esta?") print(myList.data) print(myList.length) print(myList.join(' ')) print(myList.filter(lambda x:len(x)>=10)) myList.shift() print(myList.join(' '))
# Output: {0: 'a', 1: 'b', 2: 'c'} mapped_list = myList.map(lambda x: x.upper()) print(mapped_list.data) # Output: {0: 'A', 1: 'B', 2: 'C'} filtered_list = myList.filter(lambda x: x != "b") print(filtered_list.data) # Output: {0: 'a', 2: 'c'} joined_string = myList.join("-") print(joined_string) # Output: 'a-b-c' popped_item = myList.pop() print(popped_item) # Output: 'c' shifted_item = myList.shift() print(shifted_item) # Output: 'a' myList.unshift("d") print(myList.data) # Output: {0: 'd', 1: 'b'}
Me toco con ayuda ☹️ de hecho nunca había usado shift, unshift, y también pensé que no se podía utilizar append.
Mi solución :
. . . . . . . . .. . .
class MyList: def __init__(self): self.data = {} self.length =0 pass def append(self, item): self.data[self.length]= item self.length +=1 def pop(self): response = self.data[self.length-1] del self.data[self.length-1] self.length -=1 return response pass def shift(self): response = self.data[0] del self.data[0] new ={valor-1:self.data[valor] for valor in self.data} self.data = new self.length -=1 return response def unshift(self, item): new = {valor+1:self.data[valor] for valor in self.data} new[0]= item new_2 = {key:new[key] for key in sorted(new)} self.data = new_2 self.length +=1 def map(self, func): new = MyList() for i in self.data: new.append(func(self.data[i])) return new def filter(self, func): new = MyList() for i in self.data: if func(self.data[i]): new.append(self.data[i]) return new def join(self, character=","): text = "" for i in self.data: text +=f"{self.data[i]}" +f"{character}" return text[:-1]
Mi solución
al principio no entendí que las repuesta debian ser diccionario y lo hice todo con listas, luego me toco modificar todo mi codigo * * * * * * * * *
class MyList: def __init__(self): # Tu código aquí 👇 self.data = {} self.length = 0 def append(self, item): # Tu código aquí 👇 self.data[self.length] = item self.length +=1 def pop(self): # Tu código aquí 👇 last_item = self.data[self.length-1] del self.data[self.length-1] self.length -=1 return last_item def shift(self): # Tu código aquí 👇 first_item =self.data[0] for i in range(1, self.length): self.data[i-1] = self.data[i] del self.data[self.length-1] self.length -=1 return first_item def unshift(self, item): for i in range(self.length,0,-1): self.data[i]=self.data[i-1] self.data[0]=item self.length+=1 def map(self, func): # Tu código aquí 👇 newList =MyList() for i in self.data: newList.append(func(self.data[i])) return newList def filter(self, func): # Tu código aquí 👇 newList =MyList() for i in self.data: if func(self.data[i]): newList.append(self.data[i]) return newList def join(self, character=','): # Tu código aquí 👇 string ='' for i in self.data: if i < self.length-1: string += str(self.data[i])+character else: string += str(self.data[i]) return string
o o o o o o o o
class MyList: def __init__(self): self.data = dict() self.length = 0 def append(self, item): self.data[self.length] = item self.length += 1 def pop(self): if self.length > 0: dato_eliminado = self.data[self.length - 1] self.data.pop(self.length - 1) self.length -= 1 return dato_eliminado def shift(self): if self.length > 0: dato_eliminado = self.data[0] self.data.pop(0) self.length -= 1 for i in range(1, self.length + 1): self.data[i-1] = self.data[i] self.data.pop(self.length) self.data = dict(sorted(self.data.items())) return dato_eliminado def unshift(self, item): for i in range(self.length, 0, -1): self.data[i] = self.data[i-1] self.data[0] = item self.length += 1 def map(self, func): salida = MyList() for i in range(self.length): salida.append(func(self.data[i])) return salida def filter(self, func): salida = MyList() for i in range(self.length): if func(self.data[i]) == True: salida.append(self.data[i]) return salida def join(self, character=","): salida = "" for i in range(self.length): salida += str(self.data[i]) + character return salida[0:-1]
lista = MyList() print(type(lista)) lista.append("a") lista.append("b") lista.append("c") lista.append("d") lista.append("e") lista.append("f") print("original") print(lista.data) print(lista.length) print("") print("operacion pop") print(lista.pop()) print(lista.data) print(lista.length) print("") print("operacion shift") print(lista.shift()) print(lista.data) print(lista.length) print("") print("operacion unshift") print(lista.unshift("aa")) print(lista.data) print(lista.length) print("") print("operacion map") lista1 = lista.map(lambda x: x * 3) print(lista.data) print(lista.length) print("mapeada") print(lista1.data) print(lista1.length) print("") print("operacion filter") lista2 = lista.filter(lambda x: True if len(x) > 3 else False) print(lista.data) print(lista.length) print("filtrada") print(lista2.data) print(lista2.length) print("") print("operacion join") print(lista.join("_")) print(lista.data) print(lista.length) print("")