trictionary?

Randy Bush randy at psg.com
Sun Aug 28 06:36:00 CEST 2005


i have some code which looks kinda like 

    bin = {}
    for whatever:
       for [a, b] in foo:
	  x = 42 - a
	  y = 42 - b
	  if bin.has_key(x):
	     bin[x] += 1
	  else:
	     bin[x] = 1
    for i, j in bin.iteritems():
       print i, j

now i want to add a second count column, kinda like

    bin = {}
    for whatever:
       for [a, b] in foo:
	  x = 42 - a
	  if bin.has_key(x):
	     bin[x.b] += 1
	  else:
	     bin[x.b] = 1
	     bin[x.not b] = 0
    for x, y, z in bin.iteritems():
       print x, y, z

should the dict value become a two element list, or is
there a cleaner way to do this?

randy




More information about the Python-list mailing list