Dear all,

I am new to Python, so I apologize in advance if you find my questions naive (or if they have been already answered in this forum).

1. What is the most pythonic way of mapping a list where the value each element is mapped to depends on the index of the element. Is there a way of writing the following without using zip:
        map(lambda (id,v):id*v,zip(range(len(L)),L))
I wonder whether there is something like mapInd in Oz (http://www.mozart-oz.org/documentation/base/list.html) so that you can pass a binary function to map and refer to the index of the element in the body of the given function. It would be cool to be able to simply write:
        mapInd(lambda id,v:id*v,L)

2. Is there a higher order index function that lets you specify the condition to be met by the returned element. I mean something like:

def my_index(f,L,default):
    for x in L:
        if f(x):return x
    return default

Thanks in advance for your answer!

Cheers,
Luis
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to