This example steps through recursive summation of numbers in nested lists, as presented in the chapter. It also shows how the continue statement causes the control flow to jump ahead to the next iteration.


Recursive Iteration

Q = [[2,1,9],3,[[6,7],0]]
def recursum(List):
  Accum = 0
  for item in List:
    if type(item)==int:
       Accum += item
       continue
    # if the program gets here, item is a list
    Accum += recursum(item)
  return Accum
print recursum(Q)