我有一个类似于RDD的结构:
rdd = [[[1],[2],[3]], [[4],[5]], [[6]], [[7],[8],[9],[10]]]
and I want it to become:
rdd = [1,2,3,4,5,6,7,8,9,10]
如何编写map或reduce函数使其正常工作?
我有一个类似于RDD的结构:
rdd = [[[1],[2],[3]], [[4],[5]], [[6]], [[7],[8],[9],[10]]]
and I want it to become:
rdd = [1,2,3,4,5,6,7,8,9,10]
如何编写map或reduce函数使其正常工作?
你可以例如使用flatMap
和列表推导:
rdd.flatMap(lambda xs: [x[0] for x in xs])
或者让它更加通用一些:
from itertools import chain
rdd.flatMap(lambda xs: chain(*xs)).collect()