1,python中的map,reduce,filter使用 >>> a=[1,2,3,5]
>>> map(lambda x:x+x,a)
[2, 4, 6, 10]
>>> map(lambda x:2*x,a)
[2, 4, 6, 10]
>>> reduce(lambda x,y:x*y,a)
30
>>> filter(lambda x : x%2,a)
[1, 3, 5]2,scala中的map,reduce,filter使用scala> val list2 = 1 to 10 toList
warning: there were 1 feature warning(s); re-run with -feature for details
list2: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> list2.map(x=>x*x)
res13: List[Int] = List(1, 4, 9, 16, 25, 36, 49, 64, 81, 100)
scala> list2.map(math.pow(_,2))
res14: List[Double]
...
继续阅读
(11)