Created
November 19, 2012 04:21
-
-
Save imom0/4108933 to your computer and use it in GitHub Desktop.
Count tuple-key dict element appearence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# url http://stackoverflow.com/questions/13447226/count-how-many-times-a-part-of-a-key-appears-in-a-dictionary-python | |
from collections import Counter | |
from itertools import chain | |
a = { (1,2):3, (1,3):5, (2,1):6 } | |
# first | |
# nested iter, order is important | |
Counter(j for k in a for j in k) | |
# second | |
# use chain of itertools | |
Counter(chain(*a.keys())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment