Write a Python program to triple all numbers of a given list of integers. Use Python map. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Write a Python program to triple all numbers of a given list of integers. Use Python map.

Num=[1,2,3,4,5,8] Result=map(Num*3,Num) print(Result) Why this is wrong .

23rd Mar 2022, 1:26 PM
Akash Gupta
Akash Gupta - avatar
6 Réponses
+ 3
Num=[1,2,3,4,5,8] Result= list(map(lambda x : x*3 , Num)) #to list print(Result)
23rd Mar 2022, 2:06 PM
Jayakrishna 🇮🇳
+ 2
23rd Mar 2022, 2:07 PM
Akash Gupta
Akash Gupta - avatar
+ 1
map first argument must be a function . You can create a function which return a num to num*3 and pass function to map either use lamdba expression. It returns a iterator so convert to list..
23rd Mar 2022, 1:32 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 num=[12,23,12] Result=map(lambda x:x*3,num) print (Result) this is you are saying.
23rd Mar 2022, 1:46 PM
Akash Gupta
Akash Gupta - avatar
+ 1
ravilnicki got it
23rd Mar 2022, 2:09 PM
Akash Gupta
Akash Gupta - avatar
0
Jayakrishna🇮🇳 bro solve it from lambda it is simple . So my code is wrong right?
23rd Mar 2022, 1:39 PM
Akash Gupta
Akash Gupta - avatar