recursion - Persistent objects in recursive python functions -


i trying write recursive function needs store , modify object (say set) recurses. should use global name inside function? option modify or inherit class of parameter of function can keep persistent object don't find elegant. use stack if forgo recursion altogether...

is there pythonic way of doing this? generator trick?

just pass through persistent object through recursive method.

def recursivemethod(obj_to_act_on, persistent_obj=none):      if persistent_obj == none:         persistent_obj = set()      # act on object      return recursivemethod(newobj, persistent_obj) 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -