Getting around immutable default arguments for recursion
dpapathanasiou
denis.papathanasiou at gmail.com
Wed Jan 14 17:32:30 EST 2009
> How about:
>
> def get_prior_versions (item_id, priors=None):
> """Return a list of all prior item ids starting with this one"""
> global history_db # key = item id, value = prior item id
> prior_id = history_db[item_id]
> if not prior_id:
> return priors
> else:
> if priors:
> priors.append(prior_id)
> else:
> priors = [prior_id]
> return get_prior_versions(prior_id, priors)
It's not exactly right for what I'm doing, b/c the caller always
expects a list in return.
More information about the Python-list
mailing list