Let\'s say I have a list:
y = [\'1\', \'2\', \'3\', \'4\',\'5\',\'6\',\'7\',\'8\',\'9\',\'10\']
I want to create a function that calculates
Use the sum and map functions.
sum
map
print(sum(map(int, x[num-n:num])))
The map function in Python 3 is basically a lazy version of this:
[int(i) for i in x[num-n:num]]
I'm sure you can guess what the sum function does.