Skip to content

Instantly share code, notes, and snippets.

@013231
Created November 9, 2012 14:45
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 013231/4046085 to your computer and use it in GitHub Desktop.
Save 013231/4046085 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#-*-coding:utf-8-*-
d = {
1: ['a', 'b'],
2: ['b', 'c', 'd'],
3: ['b', 'c', 'e']
}
print reduce(lambda r, k: reduce(lambda s, i: r.__setitem__(i, r.get(i, 0) + 1), set(d[k]), False) or r, d, {})
#output:
#{'a': 1, 'c': 2, 'b': 3, 'e': 1, 'd': 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment