Rob Cowie wrote: > Just forget the lists... > counters = {0:0, 1:0, 2:0, 3:0, 4:0}
Or perhaps just use a list: >>> counters = [0,0,0,0] >>> def inc(v): ... counters[v] += 1 ... >>> inc(1) >>> inc(1) >>> inc(3) >>> counters [0, 2, 0, 1] > The increment function should probably include a try:...except: Likewise for IndexErrors -- http://mail.python.org/mailman/listinfo/python-list