Skip to content

Commit 56f57f8

Browse files
mortadasrowen
authored andcommitted
[SPARK-12760][DOCS] invalid lambda expression in python example for …
…local vs cluster srowen thanks for the PR at #10866! sorry it took me a while. This is related to #10866, basically the assignment in the lambda expression in the python example is actually invalid ``` In [1]: data = [1, 2, 3, 4, 5] In [2]: counter = 0 In [3]: rdd = sc.parallelize(data) In [4]: rdd.foreach(lambda x: counter += x) File "<ipython-input-4-fcb86c182bad>", line 1 rdd.foreach(lambda x: counter += x) ^ SyntaxError: invalid syntax ``` Author: Mortada Mehyar <[email protected]> Closes #10867 from mortada/doc_python_fix.
1 parent 358a33b commit 56f57f8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

docs/programming-guide.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,12 @@ counter = 0
789789
rdd = sc.parallelize(data)
790790

791791
# Wrong: Don't do this!!
792-
rdd.foreach(lambda x: counter += x)
792+
def increment_counter(x):
793+
global counter
794+
counter += x
795+
rdd.foreach(increment_counter)
793796

794-
print("Counter value: " + counter)
797+
print("Counter value: ", counter)
795798

796799
{% endhighlight %}
797800
</div>

0 commit comments

Comments
 (0)