In the following Python code:
keyboards = [3, 1]
drivers = [5, 2, 8]
upper_limit = 10
sums = [k + d for k in keyboards for d in drivers if (k + d) <= upper_limit]
I'd like to store the result of k+d in the list comprehension so that it can be referred in the list comprehension. Is it possible in Python3?
I know that we can do the following:
sums = []
for k in keyboards:
for d in drivers:
s = k + d
if s <= upper_limit:
sums.append(s)
But I wish to avoid the side effect operation of append.