[ create a new paste ] login | about

Link: http://codepad.org/83uNtpXa    [ raw code | output | fork ]

Python, pasted on Mar 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
a = [(1, 'a'), (2, 'b'), (3, 'c'), (1, 'd')]
b = [(1, 'e'), (2, 'f')]

c = []
for a_key, a_val in a:
    c_lst = [a_val]
    for b_key, b_val in b:
        if a_key == b_key:
            c_lst.append(b_val)
    c.append((a_key, c_lst))

print(a)
print(b)
print(c)


Output:
1
2
3
[(1, 'a'), (2, 'b'), (3, 'c'), (1, 'd')]
[(1, 'e'), (2, 'f')]
[(1, ['a', 'e']), (2, ['b', 'f']), (3, ['c']), (1, ['d', 'e'])]


Create a new paste based on this one


Comments: