Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- from collections import defaultdict
- last_key = None
- running_total = 0
- chan_to_show = defaultdict(list)
- show_to_count = dict()
- chan_to_count = dict()
- for input_line in sys.stdin:
- input_line = input_line.strip()
- this_key, value = input_line.split("\t", 1)
- try:
- # See if the value is an integer, or the channel name
- value = int(value)
- if last_key == this_key:
- # While the show is the same, and it's an integer
- running_total += value
- else:
- if last_key:
- if(last_key == 'Surreal_Talking'):
- print('here2')
- # If last key is different, and it exists, store the show and it's running total
- if last_key in show_to_count:
- show_to_count[last_key] += running_total
- else:
- show_to_count[last_key] = running_total
- if(last_key == 'Surreal_Talking'):
- print(show_to_count[last_key])
- running_total = value # reset running_total to new value
- last_key = this_key # update last key
- except ValueError:
- # If it can't convert the value to int, it's channel name
- channel = value
- # If we already have the channel stored, we can append
- if channel in chan_to_show:
- # If this show is already in the channel's list, skip
- if this_key in chan_to_show[channel]:
- pass
- else:
- chan_to_show[channel].append(this_key)
- else:
- chan_to_show[channel].append(this_key)
- last_key = this_key
- for chan in chan_to_show:
- for show in chan_to_show[chan]:
- print( "{0}\t{1}\t{2}".format(show, chan, show_to_count[show]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement