-4

Please does anyone knows what is the error in this line of code ? Spend hours searching but didn't succeed to fix it. Thank youu in advance,

labels = RDD.map(lambda (a, b): a).collect()

Syntax error

AMC
  • 2,642
  • 7
  • 13
  • 35
charles
  • 209
  • 3
  • 10
  • check: https://stackoverflow.com/questions/10607293/nested-arguments-not-compiling – jxc May 02 '20 at 21:49
  • 1
    Please see [mcve], [ask], [help/on-topic]. – AMC May 03 '20 at 00:52
  • Does this answer your question? [Nested arguments not compiling](https://stackoverflow.com/questions/10607293/nested-arguments-not-compiling) – 10465355 May 03 '20 at 11:43

1 Answers1

0

If you are using python 3 probably it is about tuple unpacking that is not supported in python 3. Also you can check this thread.

Let's say you have rdd of tuples:

RDD = spark.sparkContext.range(0, 1).map(lambda a: (a, a))

below code will fail with SyntaxError: invalid syntax

RDD.map(lambda (a, b): a).collect()

but this will work correctly:

RDD.map(lambda a: a[0]).collect()
chlebek
  • 2,431
  • 1
  • 8
  • 20
  • Ok thank you . Then if i need RDD.map(lambda (a, b): b).collect() i should replace it with RDD.map(lambda a: a[2]).collect() – charles May 02 '20 at 22:27
  • My mistake, for first(a) tuple element it should be a[0] and for second(b) a[1] – chlebek May 02 '20 at 22:58