Well the deadline has come and passed, and we have a clear winner. That winner is Katie. Her solution comes in at a tiny 121 characters, with the closest solution coming from Tim with 187 characters.
The main difference came down to the fact that Katie decided to avoid using the regular expression that was given in the sample, and just parse the lines with str.split.
So without much more talking, here is the winning solution.
import sys s=sum(([l[0]]*int(l[-1])for l in map(str.split,sys.stdin)if l[-1]!='-'),[]) for x in set(s):print x,s.count(x)
It is also interesting to note how she uses the sum function to append a set of lists together.
Well done katie :D
Goes to show when you decide to use regex for one problem, you just end up with two problems ;-)
Win! :D
Just don’t try it with big numbers. :P
Well done Katie! However, this is what I achived in Ruby in 63 chars!
m=Hash.new(0);STDIN.map{|l|m[l[/^\S+/]]+=l[/\d+\s+$/].to_i};p m
:)
Leaving out regexes is just not cool:
import sys,re
d={}
exec(re.sub(‘([^\s]*).*?([^\s]*?\n)’,r’d["\1"]=d.get(“\1″,0)+\2′,sys.stdin.read()))
print d
(ok, I’m not doing as much error checking)