Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. from collections import defaultdict
  4.  
  5. last_key = None
  6. running_total = 0
  7.  
  8. chan_to_show = defaultdict(list)
  9. show_to_count = dict()
  10. chan_to_count = dict()
  11.  
  12. for input_line in sys.stdin:
  13. input_line = input_line.strip()
  14. this_key, value = input_line.split("\t", 1)
  15. try:
  16. # See if the value is an integer, or the channel name
  17. value = int(value)
  18. if last_key == this_key:
  19. # While the show is the same, and it's an integer
  20. running_total += value
  21. else:
  22. if last_key:
  23. if(last_key == 'Surreal_Talking'):
  24. print('here2')
  25. # If last key is different, and it exists, store the show and it's running total
  26. if last_key in show_to_count:
  27. show_to_count[last_key] += running_total
  28. else:
  29. show_to_count[last_key] = running_total
  30. if(last_key == 'Surreal_Talking'):
  31. print(show_to_count[last_key])
  32. running_total = value # reset running_total to new value
  33. last_key = this_key # update last key
  34. except ValueError:
  35. # If it can't convert the value to int, it's channel name
  36. channel = value
  37. # If we already have the channel stored, we can append
  38. if channel in chan_to_show:
  39. # If this show is already in the channel's list, skip
  40. if this_key in chan_to_show[channel]:
  41. pass
  42. else:
  43. chan_to_show[channel].append(this_key)
  44. else:
  45. chan_to_show[channel].append(this_key)
  46. last_key = this_key
  47. for chan in chan_to_show:
  48. for show in chan_to_show[chan]:
  49. print( "{0}\t{1}\t{2}".format(show, chan, show_to_count[show]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement