简体   繁体   中英

How to convert function to lambda

My function is below

def majority(x):
    if x > 17:
        return True
    return False

Sample lambda pseudo-code

majority = lambda x: if x > 17 return True ? False

You need to provide an expression. You can do this with python's "conditional expressions"

majority = lambda x: True if x > 17 else False

however, this just simplifies to

majority = lambda x: x > 17

Conditional expressions are of the form

value_if_true if condition else value_if_false

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