Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created March 24, 2018 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/780e3b67f2407dce88bf15ecba2b1037 to your computer and use it in GitHub Desktop.
Save Fhernd/780e3b67f2407dce88bf15ecba2b1037 to your computer and use it in GitHub Desktop.
Remoción de elementos (no hasheables) duplicados de una secuncia. OrtizOL.
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