I am trying to figure out why my groupByKey is returning the following:
[(0, ), (1,
In addition to above answers, if you want the sorted list of unique items, use following:
List of Distinct and Sorted Values
example.groupByKey().mapValues(set).mapValues(sorted)
Just List of Sorted Values
example.groupByKey().mapValues(sorted)
Alternative's to above
# List of distinct sorted items
example.groupByKey().map(lambda x: (x[0], sorted(set(x[1]))))
# just sorted list of items
example.groupByKey().map(lambda x: (x[0], sorted(x[1])))