python-vs-javascript icon indicating copy to clipboard operation
python-vs-javascript copied to clipboard

Python map() and lambda

Open igoose1 opened this issue 7 years ago • 0 comments

https://github.com/sayazamurai/python-vs-javascript/blob/444a7ab88e0c131b95f01677af22f3ad2b8d038f/index.html#L1267-L1275

In python there is an easier way to multiple each element in list:

original_list = [1, 2, 3]

new_list = list(map(lambda x: x * 2, original_list))

for x in new_list:
    print(x)

Imo, this example is more similar to js example because there is map function that exists in python too.

Unfortunately my example is difficult for understanding but we can split it for more lines:

original_list = [1, 2, 3]

f = lambda x: x * 2
new_list = list(map(f, original_list))

for x in new_list:
    print(x)

Thank you for your repository! I'm glad to meet it in github's recommendations! :+1:

igoose1 avatar Sep 15 '18 18:09 igoose1