Skip to content

Instantly share code, notes, and snippets.

@joefromct
Created April 21, 2017 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joefromct/96396162f4ee4e5028121555ba41734d to your computer and use it in GitHub Desktop.
Save joefromct/96396162f4ee4e5028121555ba41734d to your computer and use it in GitHub Desktop.
# 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