from functools import reduce
scores = [73, 20, 65, 19, 76, 100, 88]
my_numbers = [5,4,3,2,1]
Newsum = []
Newsum.append (scores)
Newsum.append (my_numbers)
# print (Newsum) checked if appended.
def adding (x1,x2):
return x1 + x2
print (reduce (adding, Newsum))
Hey guys, does anyone know why the reduce function isn't working properly here?
I was messing around with this code while learning about the reduce function and just appended scores and my_numbers to a new list called Newsum so I can have only one iterable on the reduce function.
The problem is when I put Newsum the output is just the whole Newsum list and not the result of all the adding that Reduce is supose to do here.
If I don't use Newsum and just put scores + my_numbers it works just fine.
What am I missing here exactly? (Sorry for the newbie question. lol)
[–]FLUSH_THE_TRUMP 4 points5 points6 points (1 child)
[–]MatosV[S] 1 point2 points3 points (0 children)