Sorting and ranking by key – groupByKey

@itversity
In session in Sorting and ranking by key – groupByKey when I go through, you have created a separate function using itertools.islice. But We can use like this also. Correct me if I am in wrong direction.

prdRdd = sc.textFile("/user/raghavendrakumars/sqoop_import_all_tables/products").map(lambda x: (int(x.split(",")[1]),x)).groupByKey().map(lambda x:(x[0],list(set(x[1])))).sortByKey(False)

prdRddSet = prdRdd.map(lambda x: sorted(x[1],key=lambda y: float(y.split(",")[4]),reverse=True)).map(lambda x: x[0:3]).flatMap(lambda x: x)

for i in prdRddSet.collect(): print i