再次更新!
功能更强大,更紧凑。在
*l1 = [('A', 1, 3), ('B', 2, 5), ('C', 3, 16), ('D', 4, 19), ('E', 5, 20)];
l2 = [('A', 1), ('C', 2), ('F', 8), ('D', 15), ('X',21)];
l3 = [('C', 1), ('F', 4), ('R', 16), ('D', 19), ('Z', 31)]
for k in l1,l2,l3:
# 'dummy to keep track of tuple size'
k.append(('dummy',len(k[0][1:])))
dict_lx = [ dict(map(lambda x: (x[0], x[1:]), l)) for l in l1,l2,l3 ]
sorted_keys = sorted(set(reduce(lambda x,y : x + y.keys(), dict_lx, [])))
final = map(lambda key: tuple(
[key] + reduce(lambda x,y: x + list(y.get(key, y.get('dummy')[0]*[0])), dict_lx, [])), sorted_keys)
final = filter(lambda x: x[0] != 'dummy', final)
print final
#[('A', 1, 3, 1, 0), ('B', 2, 5, 0, 0), ('C', 3, 16, 2, 1), ('D', 4, 19, 15, 19), ('E', 5, 20, 0, 0), ('F', 0, 0, 8, 4), ('R', 0, 0, 0, 16), ('X', 0, 0, 21, 0), ('Z', 0, 0, 0, 31)]
*