Suppose you have the following list: >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
My problem is that i wish to obtain the following two dictionaries: xdictstart = {'cat':10, 'dog':1} xdictend = {'cat':30, 'dog':5} Any nice way to do the above? Thanks. ------- Those interested in the above problem may consider the following code (which does not actually do what i want): >>> xdictend = dict(x) >>> xdictend {'dog': 3, 'cat': 30} >>> x [['cat', 10], ['cat', 20], ['cat', 30], ['dog', 5], ['dog', 1], ['dog', 3]] >>> xdictstart = {} >>> map(xdictstart.setdefault, *zip(*x)) [10, 10, 10, 5, 5, 5] >>> xdictstart {'dog': 5, 'cat': 10} _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers