-
-
Save parzibyte/608a88c9d19bfa074d57419e11dfec8f 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
""" | |
https://parzibyte.me/blog | |
""" | |
class Juego: | |
def __init__(self, nombre, precio): | |
self.nombre = nombre | |
self.precio = precio | |
# Método que nos dice si un objeto es igual a otro | |
# https://parzibyte.me/blog/2021/04/01/comparar-objetos-python/ | |
def __eq__(self, otro_juego): | |
return otro_juego.nombre == self.nombre and otro_juego.precio == self.precio | |
def __str__(self): | |
return f"{self.nombre}, {self.precio}" | |
def eliminar_duplicados(lista): | |
nueva_lista = [] | |
for elemento in lista: | |
if not elemento in nueva_lista: | |
nueva_lista.append(elemento) | |
return nueva_lista | |
# Fíjate que Cuphead aparece 2 veces (con el mismo precio y nombre) y Hollow Knight también | |
lista = [Juego("Cuphead", 180), Juego("Cuphead", 180), Juego( | |
"Resident Evil 2", 430), Juego("Hollow Knight", 150), Juego("Cuphead", 180), Juego("Hollow Knight", 150)] | |
sin_duplicados = eliminar_duplicados(lista) | |
print("===\nOriginal: ===\n") | |
for elemento in lista: | |
print(str(elemento)) | |
print("===\nSin repetidos===\n") | |
for elemento in sin_duplicados: | |
print(str(elemento)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment