简体   繁体   中英

How to convert a lambda function into a regular function?

a_min = [
    min(map(str.strip, x[0].split(',')),
        key=lambda i: int(str.strip(i).split('-')[-1])) for x in lst
]

I am trying to change the lambda into a regular function is there any way to do this?

It's simply a normal method with one argument, that return a value:

def min_key_method(i):
    return int(str.strip(i).split('-')[-1])

Usage:

a_min = [
    min(map(str.strip, x[0].split(',')), key=min_key_method) for x in lst
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM