Answers for "Sorts this RDD by the given keyfunc"

0

Sorts this RDD by the given keyfunc

# sortBy(keyfunc, ascending=true, numPartitions=None)

tmp = [('a', 1), ('b', 2), ('1', 3), ('d', 4), ('2', 5)]
sc.parallelize(tmp).sortBy(lambda x: x[0]).collect()
# [('1', 3), ('2', 5), ('a', 1), ('b', 2), ('d', 4)]
sc.parallelize(tmp).sortBy(lambda x: x[1]).collect()
# [('a', 1), ('b', 2), ('1', 3), ('d', 4), ('2', 5)]
Posted by: Guest on March-12-2020

Code answers related to "Sorts this RDD by the given keyfunc"

Python Answers by Framework

Browse Popular Code Answers by Language