daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Feb 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. from pprint import pprint as pp
  4.  
  5. def dedup2(items, key=None):
  6.     """ Get unique items but keep the order.
  7.         Works even with non-hashable items.
  8.     """
  9.     seen = set()
  10.     for item in items:
  11.         val = item if key is None else key(item)
  12.         if val not in seen:
  13.             yield item
  14.             seen.add(val)
  15.  
  16. logs =\
  17. [
  18.         { "ip": "1.2.3.4", "server": "reisinge.net", "id0": "2", "uri": "/", "id1": "3" },
  19.         { "ip": "1.2.3.5", "server": "reisinge.net", "id0": "2", "uri": "/", "id1": "3" },
  20.         { "ip": "1.2.3.5", "server": "reisinge.net", "id0": "2", "uri": "/", "id1": "3" },
  21. ]
  22.  
  23. logs2 = list(dedup2( logs, key=lambda d: (d['id0'], d['ip']) ))
  24. pp(logs2)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top