Lambda function to groupby first substring?

88 views Asked by At

I am trying to write a lambda function that groups words based on their first substring So the words are coming in like

a,word
b,can
a,eat
c,vegetables
b,if

So far I have a lambda function

combineddatardd.combineByKey(lambda v:\[v\],lambda x,y:x+\[y\],lambda x,y:x+y).
combineddatardd.pprint(10)

But this only gives me not the result I want. The outcome needs to be :

a,word
a,eat
b,can
b,if
c,vegetables
0

There are 0 answers