<jupyter_start><jupyter_text>______Content Copyright by <NAME>  map()map() is a built-in Python function that takes in two or more arguments: a function and one or more iterables, in the form:    map(function, iterable, ...)    map() returns an *iterator* - that is, map() returns a special object that yields one result at a time as needed. We will learn more about iterators and generators in a future lecture. For now, since our examples are so small, we will cast map() as a list to see the results immediately.When we went over list comprehensions we created a small expression to convert Celsius to Fahrenheit. Let's do the same here but use map:<jupyter_code>def fahrenheit(celsius):
    return (9/5)*celsius + 32
    
temps = [0, 22.5, 40, 100]<jupyter_output><empty_output><jupyter_text>Now let's see map() in action:<jupyter_code>F_temps = map(fahrenheit, temps)

#Show
list(F_temps)<jupyter_output><empty_output><jupyter_text>In the example above, map() applies the fahrenheit function to every item in temps. However, we don't have to define our functions beforehand; we can use a lambda expression instead:<jupyter_code>list(map(lambda x: (9/5)*x + 32, temps))<jupyter_output><empty_output><jupyter_text>Great! We got the same result! Using map with lambda expressions is much more common since the entire purpose of map() is to save effort on having to create manual for loops.  map() with multiple iterablesmap() can accept more than one iterable. The iterables should be the same length - in the event that they are not, map() will stop as soon as the shortest iterable is exhausted.For instance, if our function is trying to add two values **x** and **y**, we can pass a list of **x** values and another list of **y** values to map(). The function (or lambda) will be fed the 0th index from each list, and then the 1st index, and so on until the n-th index is reached.Let's see this in action with two and then three lists:<jupyter_code>a = [1,2,3,4]
b = [5,6,7,8]
c = [9,10,11,12]

list(map(lambda x,y:x+y,a,b))
# Now all three lists
list(map(lambda x,y,z:x+y+z,a,b,c))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09352857817666509, 'fraction_numerical': 0.01606046291922532, 'mean_word_length': 5.051428571428572, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '119429', 'license': 'MIT', 'n_tokens_mistral': 675, 'n_tokens_neox': 647, 'n_words': 300, 'path': '4-assets/BOOKS/Jupyter-Notebooks/01-Map.ipynb', 'repo_name': 'impastasyndrome/Lambda-Resource-Static-Assets', 'size': '2123'}