Advertisement
Fhernd

remover-duplicados-no-hasheables.py

Mar 24th, 2018
1,214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def remover_duplicados(secuencia, funcion_hash = None):
  2.     elementos_iterados = set()
  3.    
  4.     for elemento in secuencia:
  5.         valor = elemento if funcion_hash is None else funcion_hash(elemento)
  6.        
  7.         if valor not in elementos_iterados:
  8.             yield valor
  9.             elementos_iterados.add(valor)
  10.            
  11.  
  12. lista_diccionarios = [{'x':2,'y':3} ,{'x':2,'y':5}, {'x':2,'y':3}, {'x':3,'y':5}]
  13.  
  14. print(list(remover_duplicados(lista_diccionarios, funcion_hash = lambda d: (d['x'], d['y']))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement