nodes: 0, module; 1, function_definition; 2, function_name:flatMap; 3, parameters; 4, block; 5, identifier:self; 6, identifier:f; 7, default_parameter; 8, expression_statement; 9, function_definition; 10, return_statement; 11, identifier:preservesPartitioning; 12, False; 13, comment:"""
          Return a new RDD by first applying a function to all elements of this
          RDD, and then flattening the results.
  
          >>> 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)]
          """; 14, function_name:func; 15, parameters; 16, block; 17, call; 18, identifier:s; 19, identifier:iterator; 20, return_statement; 21, attribute; 22, argument_list; 23, call; 24, identifier:self; 25, identifier:mapPartitionsWithIndex; 26, identifier:func; 27, identifier:preservesPartitioning; 28, attribute; 29, argument_list; 30, identifier:chain; 31, identifier:from_iterable; 32, call; 33, identifier:map; 34, argument_list; 35, call; 36, identifier:iterator; 37, identifier:fail_on_stopiteration; 38, argument_list; 39, identifier:f
code: def flatMap(self, f, preservesPartitioning=False):
          """
          Return a new RDD by first applying a function to all elements of this
          RDD, and then flattening the results.
  
          >>> 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)]
          """
          def func(s, iterator):
              return chain.from_iterable(map(fail_on_stopiteration(f), iterator))
          return self.mapPartitionsWithIndex(func, preservesPartitioning)