Hey,

I started with this:

factByClass = {}

def update(key, x0, x1, x2, x3):
    x = factByClass.setdefault(key, [ [], [], [], [] ])
    x[0].append(x0)
    x[1].append(x1)
    x[2].append(x2)
    x[3].append(x3)

update('one', 1, 2, 3, 4)
update('one', 5, 6, 7, 8)
update('two', 9, 10, 11, 12)

print factByClass

{'two': [[9], [10], [11], [12]], 'one': [[1, 5], [2, 6], [3, 7], [4,
8]]}

I then 'upgraded' to this:

def update(key, *args):
    x = factByClass.setdefault(key, [[], [], [], [] ])
    for i, v in enumerate(args):
        x[i].append(v)

Is there a better way?
Cheers!

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to