"map" takes a function and a list, applies the function to each item in
a list, and returns the result list. For example:
>>> def f(x): return x + 4
>>> numbers = [4, 8, 15, 16, 23, 42]
>>> map(f, numbers)
[8, 12, 19, 20, 27, 46]
So, rather that ask if there is a different way to write f, I'd j
Ronny Mandal wrote:
> Assume you have a mathematical function, e.g. f(x) = x + 4
>
> To calculate all the values from 1 to n, a loop is one alternative.
>
Numeric and friends (numarray,numpy) have something like numarray.arange
- they return arrays similar to the lists returned by standard libs
Are you looking for the "map" function?
>>> def f(x): return x+4
>>> map(f, [1,2,3,3,70])
[5, 6, 7, 7, 74]
CyrilOn 2/28/06, Ronny Mandal <[EMAIL PROTECTED]> wrote:
Assume you have a mathematical function, e.g. f(x) = x + 4To calculate all the values from 1 to n, a loop is one alternative.But to m