<jupyter_start><jupyter_text>Built-in functions for working with iteratorsThese functions are always available. You don't need to import them. `zip()`: linking elements from multiple iteratorsWithout `zip()`:<jupyter_code>species_list = ['Whale', 'Lizard', 'Ant']
class_list = ['Mammal', 'Reptile', 'Insect']
cuteness_list = [3, 2, 1, 0]

for i in range(len(species_list)):
    species = species_list[i]
    class_ = class_list[i]
    print('%s is a %s' % (species, class_))<jupyter_output>Whale is a Mammal
Lizard is a Reptile
Ant is a Insect<jupyter_text>With `zip()`:<jupyter_code>for species, class_, cuteness in zip(species_list, class_list, cuteness_list):
    print('%s is a %s and has a cuteness rating of %d' % (species, class_, cuteness))<jupyter_output>Whale is a Mammal and has a cuteness rating of 3
Lizard is a Reptile and has a cuteness rating of 2
Ant is a Insect and has a cuteness rating of 1<jupyter_text>map(): applying a function to each element from an iteratorThe first argument is a function. The second argument is an iterator. The function should take an element as a single argument.<jupyter_code>from math import sqrt
fibonacci = [1,1,2,3,5,8]
for i in map(sqrt, fibonacci):
    print(i)<jupyter_output>1.0
1.0
1.4142135623730951
1.7320508075688772
2.23606797749979
2.8284271247461903<jupyter_text>An equivalent generator expresssion:<jupyter_code>for i in (sqrt(j) for j in fibonacci):
    print(i)<jupyter_output>1.0
1.0
1.4142135623730951
1.7320508075688772
2.23606797749979
2.8284271247461903<jupyter_text>enumerate(): getting indices along with elements Without `enumerate()`:<jupyter_code>i = 0
for species in species_list:
    print(i, species)
    i += 1<jupyter_output>0 Whale
1 Lizard
2 Ant<jupyter_text>With `enumerate()`:<jupyter_code>for i, species in enumerate(species_list):
    print(i, species)<jupyter_output>0 Whale
1 Lizard
2 Ant<jupyter_text>An equivalent generator expression:<jupyter_code>for i, species in ((i, species_list[i]) for i in range(len(species_list))):
    print(i, species)<jupyter_output>0 Whale
1 Lizard
2 Ant<jupyter_text>filter(): excluding elements Without `filter()`:<jupyter_code>for i in fibonacci:
    if i%2:
        continue
    print(i)<jupyter_output>2
8<jupyter_text>With `filter()`:<jupyter_code>for i in filter(lambda i: not i%2, fibonacci):
    print(i)<jupyter_output>2
8<jupyter_text>An equivalent generator expression:<jupyter_code>for i in (j for j in fibonacci if not j%2):
    print(i)<jupyter_output>2
8
{'fraction_non_alphanumeric': 0.10678442392613409, 'fraction_numerical': 0.06945002007226013, 'mean_word_length': 5.960893854748603, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '437404', 'license': 'Unlicense', 'n_tokens_mistral': 1029, 'n_tokens_neox': 928, 'n_words': 265, 'path': 'Functional_Thinking/Lab/30A-convenience-functions.ipynb', 'repo_name': 'Anekenonso/FirstYear', 'size': '2491'}