Start by using zip to combine the items.
Multiple lists.
>>> list(zip(['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']))
[('1', '4', '7'), ('2', '5', '8'), ('3', '6', '9')]
Transposing a lists of list using zip(*thelist)
- rows,columns -> columns,rows -
a = [[1,2,3],
[4,5,6],
[7,8,9]]
>>> list(zip(*a))
[(1, 4, 7),
(2, 5, 8),
(3, 6, 9)]
b = [['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9']]
>>> list(zip(*b))
[('1', '4', '7'),
('2', '5', '8'),
('3', '6', '9')]
Once you have done that you can iterate and combine. All have a similar pattern: call a function/method passing the combined values.
Summing numbers
>>> [sum(thing) for thing in zip(*a)]
[12, 15, 18]
>>> list(map(sum, zip(*a)))
[12, 15, 18]
adding/concatenating/joining strings
>>> [''.join(thing) for thing in zip(*b)]
['147', '258', '369']
>>> list(map(''.join, zip(*b)))
['147', '258', '369']
Combining list of strings with list of numbers.
>>> x = ['a', 'b', 'c']
>>> y = [1,2,3]
>>> z = ['g', 'e', 'h']
>>> [''.join(str(item) for item in thing) for thing in zip(x,y,z)]
['a1g', 'b2e', 'c3h']
>>> [''.join(map(str,thing)) for thing in zip(x,y,z)]
['a1g', 'b2e', 'c3h']
Apply function to list of list elementwise.
>>> def f(args):
... a,b,c,*_ = args
... return (a+b)**c
>>> [f(thing) for thing in zip(*a)]
[78125, 5764801, 387420489]