Reputation: 11
in Python 3.2 How do I alter items in a list with a function and return the result of the function over the item and the item itself before altering? 10x
def some(func,seq):
# What to do here?
Upvotes: 1
Views: 539
Reputation: 46607
Something like
def func(my_func,seq):
return seq, [my_func(n) for n in seq]
or
def func(my_func,seq):
return [(my_func(n),n) for n in seq]
... your description is not very clear in that regard.
What's being used here is a list comprehension. my_func
is called once for every element in seq
and should return the function value for this element.
Upvotes: 3