Lambda Function Use instead of Regular Function

Hello Everyone, I have one question here, Why are we making function when we can use Lambda Function for One-Liner.

Looking for your Prompt and Positive response.
My Code:

def label_genres(row):
    """For each segment in `genres_mean`,
    labels the apps that cost less than its segment's mean with `1`
    and the others with `0`."""

    aff = row["affordability"]
    gc = row["genre_count"]
    price = row["Price"]

    if price < genres_mean.loc[(aff, gc)][0]:
        return 1
        return 0


The answer is very simple: readability.

If you came up with a lambda function that is simpler than the rationale implemented by label_genres, Iā€™d love it if you shared it with us!

1 Like