For Guido and developers Python.
Ype Kingma
ykingma at accessforall.nl
Thu May 15 00:25:30 EDT 2003
Quiet wrote:
> For Guido and developers Python.
> Hello.
> There is a problem.
> At creation of slice created the copy of elements of the list.
> For many recursive algorithms it would be convenient to create
> a slice as the alias (link) to the list.
>
> Example:
>
> lst_List =.....
>
> def f (lst_List):
> ....
> f (lst_List [i:j])
>
> Thus it is necessary, that the list was one. It is necessary that
> copies were not created.
>
> For this purpose I suggest to enter a new key word "aslink".
>
> Example:
>
> f(lst_List [i:j] aslink)
>
> It is possible to make so:
> 1. When it is necessary to make a copy of object obviously:
> "ascopy":
>
> a = b ascopy
You can use:
a = b.copy()
> 2. It is not necessary to create a copy of object.
> The obvious reference to object: aslink:
>
> a = b aslink
Simply use:
a = b
> f(lst_List [i:j] aslink)
You can solve this by defining another function f2
def f2(lst_List, i, j): ...
and always indexing lst_List in f2 with i added to
the index. You might also assert that any resulting
index is smaller than j.
You could use a separate class to encapsulate the
arguments of f2.
Since python does not optimize for tail recursion
you might also change evt. tail recursion to a loop.
Have fun,
Ype
--
email at xs4all.nl
More information about the Python-list
mailing list