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
Post a Comment