flat map python code example
Example 1: flatmap python
array = [[1, 2], [3, 4]]
flatArray = [element for element in innerArray for innerArray in array]
Example 2: flatmap in python
rdd2=rdd.flatMap(lambda x: x.split(" "))
for element in rdd2.collect():
print(element)
Example 3: flatmap in python
data = ["Project Gutenberg’s",
"Alice’s Adventures in Wonderland",
"Project Gutenberg’s",
"Adventures in Wonderland",
"Project Gutenberg’s"]
rdd=spark.sparkContext.parallelize(data)
for element in rdd.collect():
print(element)