Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import sys
- import datetime
- import operator
- oldKey = None
- counter = 0
- countarray = {} # dictionary
- oldHrs = None
- for line in sys.stdin:
- data = line.strip().split("\t")
- if len(data) != 2:
- continue
- userid,newHrs = data # data that is taken from the array
- if oldKey and oldKey != userid: # on first pass, olkey is not going to equal user id
- countarray[newHrs] = 1
- print userid,"\t", max(countarray.iterkeys(), key=lambda k: countarray[k])
- else: # so we insert the hr (as the key) and a 1 for (the value)
- # if oldkey is equal to userid, then
- if newHrs in countarray:
- countarray[newHrs] += 1
- #countarray.update({newHrs:1})
- else:
- countarray[newHrs] = 1
- oldKey = userid
- oldHrs = newHrs
- countarray = {} # then we rest the dictionary
- if oldKey != None:
- #print userid,"\t", max(countarray.iterkeys(), key=lambda k: countarray[k])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement