Skip to content

Instantly share code, notes, and snippets.

@ODiogoSilva
Created September 13, 2017 17:58
Show Gist options
  • Save ODiogoSilva/d0af91ea22c00420b261b2b29059c7f3 to your computer and use it in GitHub Desktop.
Save ODiogoSilva/d0af91ea22c00420b261b2b29059c7f3 to your computer and use it in GitHub Desktop.
duplicates removal on the fly
from collections import defaultdict
your_dict = {}
lookup_table = defaultdict(list)
for line in file_handle:
acc, fields = get_fields(line)
for i in fields:
# Dunno if this happens at all
if acc in lookup_table[i]:
lookup_table[i].append(acc)
your_dict[acc] = [x for x in fields if x not in lookup_table[acc]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment