Update counter.py with defaultdict

Compatible (and preferred) with Python 2.5+.