开发者

Python lists and iterables

开发者 https://www.devze.com 2023-02-21 14:50 出处:网络
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 itsel开发者_如何转开发f before altering? 10x

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 itsel开发者_如何转开发f before altering? 10x

def some(func,seq):
    # What to do here?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消