I don't know how this lambda function works

Question:

def run_lambda_check():
    """This function help me to input run in one line and i know its not the best way to do it"""
    run = True
    while run:
        run = (lambda check: True if check == "y" else False)(input("Do you want to draw more? "))

I’m working on making my first simplified python game, blackjack to be exact. The code i’ve made is just, hurts my eyes.
Thats why im trying to fix it by make it with less lines or make it become more readable. In this case im trying to reduce the number of lines. To be honest i dont feel comfortable doing this again and again whenever i want to ask user if they want to continue doing something or not. (because the code is hard to read, tbh i dont know this will work before i tried to write and fix it)
So my question is, there are better ways to do it in one line, can you guys show me any of it which u usually use in reality, or should i just make a function to do this alone?

Answers:

Your code might be ameloriated to not use lambda at all following way

def run_lambda_check():
    run = True
    while run:
        run = (input("Do you want to draw more? ") == "y")

Observe that == comparison already gives True or False so there is not need to wrap it inside ternary operator.

Answered By: Daweo
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.