欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python & Javascript Map one list vs Two lists

程序员文章站 2022-06-24 19:08:46
Map one listIn [119]: aOut[119]: [1, 2, 3]In [120]: list(map(lambda x : 100* x , a))Out[120]: [100, 200, 300]Map Two listIn [116]: aOut[116]: [1, 2, 3]In [117]: bOut[117]: [10, 20, 30]In [118]: list(map(lambda x, y : x + y , a,b))Out[118]: [...

Python Map one list

In [119]: a
Out[119]: [1, 2, 3]

In [120]: list(map(lambda x : 100* x , a))
Out[120]: [100, 200, 300]

Python Map Two list

In [116]: a
Out[116]: [1, 2, 3]

In [117]: b
Out[117]: [10, 20, 30]

In [118]: list(map(lambda x, y : x + y , a,b))
Out[118]: [11, 22, 33]

Using Operator

In [124]: from operator import add

In [125]: a
Out[125]: [1, 2, 3]

In [126]: b
Out[126]: [10, 20, 30]

In [127]: list(map(add, a, b))
Out[127]: [11, 22, 33]

In [128]: from operator import mul

In [129]: list(map(mul, a, b))
Out[129]: [10, 40, 90]

In [130]: 

JS Map One, Two list

a = [1,2,3]
b = [10,20,30]

// Map 1 list
console.log('Map 1 ist')
result = a.map((value)=>value*10)
console.log(result);

// Map 2 lists
console.log('Map 2 lists')
result = a.map((value,index) => value * b[index])
console.log(result);

Output

inakamono@ninja MINGW64 ~/wk/coding/hello_node
$ node mapping.js
Map 1 ist
[ 10, 20, 30 ]
Map 2 lists
[ 10, 40, 90 ]

本文地址:https://blog.csdn.net/fimtestxyz/article/details/109257653

相关标签: python js