Generalized slicing and a question on lambdas

Anton Hartl (hartl@Informatik.TU-Muenchen.DE)
16 Sep 1994 14:57:31 GMT

Some things and ideas that came into my mind while writing some python code ...
(Eventually I haven't studied the manuals well enough ... in that case
forgive my ignorance :))

* Generalized slicing, projection facility

What about having a way to specify an arbitrary number of
arbitrary elements of a sequence? E.g.

sequence_object [ 4:2 ; 1 ; 1 ; 8 ]

I came across that when I tried to extract just year and day from
the call to localtime() (which yields a tuple year,month,day,... )
and would have prefered to write

year, month = localtime(time())[0;2]

instead of

x = localtime(time())
year, month = x[0], x[2]

* How is the syntax for calling a lambda expression with arguments?

I.e. what is the python equivalent of the following Scheme expression?

((lambda (n) (+ n 1)) 10)

I actually tried that in the context of converting a list to tuple
and I tried to get something like that to work

lambda l: l[0], l[1] ( [1, 2] )

and many variants thereof but couldn't find one that worked.

Alternatively is there a way (other than writing it in python) to
convert from a tuple to a list and vice versa? There are such
operations for the array type, at least you can fill an array
from a list and convert the array to a list.

Thx in advance for any feedback
-Toni