Recursive algorithms anyone?

Greg Jorgensen gregj at
Thu Jun 7 03:53:50 EDT 2001

How about this. Ignore the "lists" list to get the "other" behavior.

from __future__ import nested_scopes

def additem(items, k):
    from types import ListType

    def _additem(items, k):
        if id(items) not in lists:
            i = 0
            for x in items:
                if type(x) is ListType:
                    _additem(x, k)
                    items[i] = x + k
                i += 1

    lists = []
    _additem(items, k)

Greg Jorgensen
PDXperts LLC
Portland, Oregon, USA
gregj at

More information about the Python-list mailing list