Created
May 4, 2013 07:08
-
-
Save bigsnarfdude/5516567 to your computer and use it in GitHub Desktop.
dict processing
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
data = open('sequence', 'r').readlines() | |
elements = {} | |
for line in data: | |
(user, element, js_time) = line.split("\t") | |
if element not in elements: | |
elements[element] = 1 | |
else: | |
elements[element] += 1 | |
sorted_counted = elements.items() | |
sorted_counted.sort( key=lambda a:(-a[1],a[0]) ) | |
print sorted_counted[0:10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment