code: def mapPartitions(self, f, preservesPartitioning=False):
          
          def func(s, iterator):
              return f(iterator)
          return self.mapPartitionsWithIndex(func, preservesPartitioning)
docs: Return a new RDD by applying a function to each partition of this RDD.
  
          >>> rdd = sc.parallelize([1, 2, 3, 4], 2)
          >>> def f(iterator): yield sum(iterator)
          >>> rdd.mapPartitions(f).collect()
          [3, 7]