<jupyter_start><jupyter_text>Functional Programming in PythonInterest in Functional Programming is currently growing as more developers become aware of the benefits it offers, particularly with respect to concurrency and scale.For some background on Functional Programming see the paper 'Why Functional Programming Matters: http://www.cse.chalmers.se/~rjmh/Papers/whyfp.pdfThere are several aspects of Python that support a functional programming style.For example: `map`, `reduce` and `filter`.  Map`map` applies a function to all the items in an input sequence.```pythonmap(function, sequence)```For example:```pythonsequence = [1, 2, 3, 4, 5]def square(x):    return x**2   result = list(map(square, sequence))print(result)```Run the code below to see the output.<jupyter_code>sequence = [1, 2, 3, 4, 5]

def square(x):
    return x**2
   
result = list(map(square, sequence))
print(result)<jupyter_output><empty_output><jupyter_text>Filter`fiter` takes in a sequence and returns a sequence containing only those elements of the sequence for which a function when applied to the element returns true.`filter(function, sequence)`For example:```pythonsequence = range(-10, 10)greater_than_zero = list(filter(lambda x: x > 0, sequence))print(greater_than_zero)```<jupyter_code>sequence = range(-10, 10)
greater_than_zero = list(filter(lambda x: x > 0, sequence))
print(greater_than_zero)<jupyter_output><empty_output><jupyter_text>Reduce`reduce` performs computations on a sequence and returns a single result.`reduce(function, sequence)`For example:```pythonfrom functools import reduceproduct = reduce((lambda x, y: x * y), [1, 2, 3, 4])print(product)```At each step the function passed to `reduce` is passed two arguments, the current reduced value and the next value from the sequence. By default, the first item in the sequence is used as the initial value of the reduction value.<jupyter_code>from functools import reduce
product = reduce((lambda x, y: x * y), [1, 2, 3, 4])
print(product)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10320987654320987, 'fraction_numerical': 0.014814814814814815, 'mean_word_length': 6.448529411764706, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '519618', 'license': 'MIT', 'n_tokens_mistral': 615, 'n_tokens_neox': 571, 'n_words': 223, 'path': 'Functional Programming in Python.ipynb', 'repo_name': 'JohnCrickett/PythonExample', 'size': '2025'}