You can use the below code to do this:
rdd=sc.textfile(inputfile)
wc=rdd.flatMap(lambda line: line.split()).map(lambda w : (w,1)).reduceByKey(lambda a,b:a+b).map(lambda (a,b) : (b,a)).sortByKey(ascending=True)
output=sc.collect()
for (count, word) in output:
print("%s %i",(word, count))