File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -690,6 +690,26 @@ def collectAsMap(self):
690690 """
691691 return dict (self .collect ())
692692
693+ def keys (self ):
694+ """
695+ Return an RDD with the keys of each tuple.
696+ >>> m = sc.parallelize([(1, 2), (3, 4)]).keys()
697+ >>> m.collect()
698+ [1, 3]
699+ """
700+ map_only_keys_fn = lambda (k , v ): k
701+ return self .map (map_only_keys_fn )
702+
703+ def values (self ):
704+ """
705+ Return an RDD with the values of each tuple.
706+ >>> m = sc.parallelize([(1, 2), (3, 4)]).values()
707+ >>> m.collect()
708+ [2, 4]
709+ """
710+ map_only_values_fn = lambda (k , v ): v
711+ return self .map (map_only_values_fn )
712+
693713 def reduceByKey (self , func , numPartitions = None ):
694714 """
695715 Merge the values for each key using an associative reduce function.
You can’t perform that action at this time.
0 commit comments