<jupyter_start><jupyter_text>Raw Python - Lambda Functions<jupyter_code>x = range(10)
x
[item**2 for item in x]
def square(num):
    return num**2
list(map(square, x))
square_lamb = lambda num: num**2
list(map(square_lamb, x))<jupyter_output><empty_output><jupyter_text>Lambda functions are just anonymous functions and don't need to be created as official functions prior to being used. This makes them useful because they can really help with code readability (if used appropriately). Their true power comes from their expressiveness when performing inline operations.I'm sure that sounds abstract at this point but I figured it would lay good ground work for our example<jupyter_code>list(map(lambda num: num**2, x))<jupyter_output><empty_output><jupyter_text>square every number that is divisible by 2 from 1 to 20<jupyter_code>[item**2 for item in range(1,20) if item % 2 == 0]<jupyter_output><empty_output><jupyter_text>That’s a little abstract at this point...We'll get to those with map, filter, and reduce below Now obviously this is not appropriate for everything but I just want you to understand that lambda functions are just anonymous functions.<jupyter_code>list(map(lambda z: z**2, filter(lambda z: z % 2 == 0, range(1,20))))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08811959087332809, 'fraction_numerical': 0.01730920535011802, 'mean_word_length': 6.395348837209302, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '424507', 'license': 'Apache-2.0', 'n_tokens_mistral': 393, 'n_tokens_neox': 375, 'n_words': 153, 'path': '2- IPython Notebooks and Raw Python Data Analysis/2-4 Raw Python - Lambda Functions.ipynb', 'repo_name': 'zengyanjulia/Python', 'size': '1271'}