<jupyter_start><jupyter_text>Python Lambda **lambda** A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only return one expression. The identity function is a function that returns its argument:<jupyter_code>def identity(x):
    return(x)
identity(1)<jupyter_output><empty_output><jupyter_text>Let's write the identity function using Python lambda construction:<jupyter_code># We only need one line of code
identity_lambda = lambda x : x
identity_lambda(1)<jupyter_output><empty_output><jupyter_text>This is a lambda function that adds 100 to the number passed as an argument<jupyter_code>add_100 = lambda a: a + 100
add_100(5)
add_100(1000)<jupyter_output><empty_output><jupyter_text>Lambda functions can take any number of arguments:<jupyter_code>add2 = lambda a, b : a + b
add2(4,6)
add2(10,20)
add3 = lambda a, b, c : a + b + c
add3(10,20,30)<jupyter_output><empty_output><jupyter_text>Why use lambda functions?The power of lambda is better shown when you use them as an anonymous function inside another function.<jupyter_code>def myfunc(n):
    return lambda a : a * n<jupyter_output><empty_output><jupyter_text>Let's make a function that doubles the number you send in:<jupyter_code>mydoubler = myfunc(2)
mydoubler(10)
mydoubler(2)<jupyter_output><empty_output><jupyter_text>Let's make a function that triples the number you send in:<jupyter_code>mytripler = myfunc(3)
mytripler(10)
mytripler(2)
mydoubler(2) * mytripler(2)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09084924292297564, 'fraction_numerical': 0.03225806451612903, 'mean_word_length': 7.306010928961749, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '219987', 'license': 'MIT', 'n_tokens_mistral': 549, 'n_tokens_neox': 514, 'n_words': 156, 'path': '02-Basic Python/10-Lambda.ipynb', 'repo_name': 'Goliath-Research/Introduction-to-Data-Science', 'size': '1519'}