Efficient implementation of deeply nested lists

Bengt Richter bokr at oz.net
Fri Jan 20 04:30:29 CET 2006

On 19 Jan 2006 01:19:06 -0800, "Kay Schluehr" <kay.schluehr at gmx.net> wrote:

>I want to manipulate a deeply nested list in a generic way at a
>determined place. Given a sequence of constant objects a1, a2, ..., aN
>and a variable x. Now construct a list from them recursively:
>L = [a1, [a2, [....[aN, [x]]...]]
>The value of x is the only one to be changed. With each value of x a
>new instance of L is needed so that we actually have a function:
>L = lambda x: [a1, [a2, [....[aN, [x]]...]]
>I'm seeking for an efficient implementation that does not recompute the
>whole list each time. Any ideas?
Make a custom class factory that makes a class with a1..aN and can be instantiated
with x, producing an object that behaves like L

So the question in my mind is, how are you actually going to use these "L" things?

Bengt Richter

More information about the Python-list mailing list