Created
March 24, 2018 17:16
-
-
Save Fhernd/780e3b67f2407dce88bf15ecba2b1037 to your computer and use it in GitHub Desktop.
Remoción de elementos (no hasheables) duplicados de una secuncia. OrtizOL.
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
def remover_duplicados(secuencia, funcion_hash = None): | |
elementos_iterados = set() | |
for elemento in secuencia: | |
valor = elemento if funcion_hash is None else funcion_hash(elemento) | |
if valor not in elementos_iterados: | |
yield valor | |
elementos_iterados.add(valor) | |
lista_diccionarios = [{'x':2,'y':3} ,{'x':2,'y':5}, {'x':2,'y':3}, {'x':3,'y':5}] | |
print(list(remover_duplicados(lista_diccionarios, funcion_hash = lambda d: (d['x'], d['y'])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment