Sounds like you're looking for something along the lines of
[sum(t) for t in itertools.product(l1, l2, l3)]
which results in
[16, 20, 26, 19, 24, 28, 34, 27, 22, 26, 32, 25, 13, 17, 23, 16, 21, 25, 31, 24, 19, 23, 29,
22, 12, 16, 22, 15, 20, 24, 30, 23, 18, 22, 28, 21]
Here itertools.product
generates the Cartesian product of the input iterables. If you had some unknown number of iterables in a list you could do
iterables = [l1, l2, l3, ...]
[sum(t) for t in itertools.product(*iterables)]
to unpack them into arguments
A recursive solution would looks something like this. Warning: it is going to be worse in every way compared to the itertools
solution.
def summations(*iterables, sums=()):
if not iterables:
return list(sums)
head, *tail = iterables
if not sums:
return summations(*tail, sums=head)
sums = (x+y for y in sums for x in head)
return summations(*tail, sums=sums)
summations(l1, l2, 3)
# [16, 20, 26, 19, 24, 28, 34, 27, 22, 26, 32, 25, 13, 17, 23, 16, 21, 25, 31, 24, 19, 23, 29,
# 22, 12, 16, 22, 15, 20, 24, 30, 23, 18, 22, 28, 21]