Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I invert key and value in RDD in Python 3 pyspark?

This works in Python 2.7, but in Python 3.5 it returns

SyntaxError: invalid syntax.

I'm not sure if this has to do with the fact that "tuple unpacking" was removed from Python 3, as I read on another post, or is a different issue.

rddInverted = rdd.map(lambda (x,y): (y,x))
like image 610
Deana H. Avatar asked Dec 04 '22 00:12

Deana H.


1 Answers

Try something like this:

rddInverted = rdd.map(lambda x: (x[1], x[0]))

I hope it will work

like image 172
Thiago Baldim Avatar answered Dec 06 '22 13:12

Thiago Baldim