+ 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. 👍🏻

20th Mar 2019, 11:15 PM
tristach605
tristach605 - avatar
8 Respostas
+ 8
2**2 == 4 3**2 == 9
21st Mar 2019, 12:05 AM
HonFu
HonFu - avatar
+ 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 ☺
21st Mar 2019, 12:52 AM
Solo
Solo - avatar
+ 4
2**2= 2*2=4 2**3= 2*2*2=8
21st Mar 2019, 1:18 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 4
tristach605 Your lambda says x**2, not x**3 or x**x
21st Mar 2019, 6:58 AM
Anna
Anna - avatar
+ 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.
21st Mar 2019, 1:04 AM
tristach605
tristach605 - avatar
+ 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 ()....
22nd Mar 2019, 1:49 AM
Adnan Zawad Toky
Adnan Zawad Toky - avatar
0
2**2=2x2=4 How do you come to 2x2x2?
17th Apr 2019, 5:13 AM
Karsten Stiegler
Karsten Stiegler - avatar
0
I have since edited the post as AZT noted.
17th Apr 2019, 8:21 AM
tristach605
tristach605 - avatar