Created
April 21, 2017 18:55
-
-
Save joefromct/96396162f4ee4e5028121555ba41734d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# given a list like this: | |
the_list = [1,2,3,4,5] | |
# We could call do_something() for each item in the list like this: | |
for li in the_list: | |
do_something(li) | |
# This is a recursive self-calling function to do the same | |
def joes_loop(the_list): | |
if the_list: # anything left? | |
do_something(the_list[0]) # do somethnig on the first item of the list | |
joes_loop(the_list[1:]) # call ourself with the rest of the list | |
# One will work in map-reduce, spark, parallel, the other won't.... | |
# this is because the iterator (li) is a side-effect, a "temp variable" that is | |
# not thread-safe (simply put) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment