简体   繁体   English

使用 lambda 表达式理解 map() function 的概念

[英]Understanding the concept of map() function using lambda expression

What does this (x[1],0) part transform?这个(x[1],0)部分转换了什么?

rdd.map(lambda x : (x[1],0))

For each item in rdd it creates a tuple.它为 rdd 中的每个项目创建一个元组。 For that rdd item ( x ), the second value of that rdd item ( x[1] ), is placed in the tuple being created along with the number 0 .对于该 rdd 项 ( x ),该 rdd 项的第二个值 ( x[1] ) 与数字0一起放置在正在创建的元组中。

I don't have pyspark installed, so I'm just using the built in map function to show how this transformation would work:我没有安装 pyspark,所以我只是使用内置的 map function 来展示这个转换是如何工作的:

>>> rdd = ['ab', 'xyz', 'jk', 'pq']
>>> list(map(lambda x : (x[1],0), rdd)) 
[('b', 0), ('y', 0), ('k', 0), ('q', 0)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM