+ 5
Python Lambda List Range Question
i = list (range(1,4)) s = list (map(lambda x:x**2,i)) print(sum(s)) Solution: 14 Map lambda is asking me to repeat a function? #NOTE! I've since edited my post for errors. Thanks to all. 👍🏻
8 Respostas
+ 8
2**2 == 4
3**2 == 9
+ 6
tristach605
list(range(1,4)) is a range from 1 to 3 inclusive, which means:
"i = [1,2,3]";
"x**2" is "x" squared;
print(sum(s)) =>
print(sum(1*1, 2*2, 3*3)) =>
print(1+4+9) => 14 ☺
+ 4
2**2= 2*2=4
2**3= 2*2*2=8
+ 4
tristach605 Your lambda says x**2, not x**3 or x**x
+ 2
Thanks! Any idea why range is only 1-3 (not 1-4)?
Also, 2**2 is 4? 2x2x2 should be 8, shouldn't it?
Sorry for the confusion and thanks for any help you could provide.
+ 2
You have written 3**3=27. But it should be 3**2=9. Also you have a syntax error at line 2. You have not closed the ()....
0
2**2=2x2=4
How do you come to 2x2x2?
0
I have since edited the post as AZT noted.