| [ Web Proxy ] |
| Viewing: https://spark.apache.org/docs/latest/api/python/reference/api/../api/pyspark.RDD.flatMap.html | [Back] [Original] |
Site Navigation
Site Navigation
Section Navigation
Return a new RDD by first applying a function to all elements of this RDD, and then flattening the results.
New in version 0.7.0.
a function to turn a T into a sequence of U
indicates whether the input function preserves the partitioner, which should be False unless this is a pair RDD and the input function doesnt modify the keys
Examples
>>> rdd = sc.parallelize([2, 3, 4])
>>> sorted(rdd.flatMap(lambda x: range(1, x)).collect())
[1, 1, 1, 2, 2, 3]
>>> sorted(rdd.flatMap(lambda x: [(x, x), (x, x)]).collect())
[(2, 2), (2, 2), (3, 3), (3, 3), (4, 4), (4, 4)]
Copyright @ 2026 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.
Created using Sphinx 4.5.0.
Built with the PyData Sphinx Theme 0.13.3.
| Web Proxy Viewer | New URL | Original Page |