<jupyter_start><jupyter_text>Memory of Genrators Vs Iterators 😇 - For the generator's work, you need to keep in memory the variables of the generator function.- But you don't have to keep the entire collection in memory, so usually this is EXACTLY the trade-off you want to make.<jupyter_code>%%memit
g = generators(range(10**8))
print(sum(g))
%%memit
i = iterators(range(10**8))
print(sum(i))<jupyter_output>4711503365894179
peak memory: 8475.12 MiB, increment: 1644.42 MiB<jupyter_text>Performance of Genrators Vs Iterators 😃<jupyter_code>%%time
g = generators(range(10**8))
print(sum(i))
%%time
i = iterators(range(10**8))
print(sum(i))<jupyter_output>4711503365894179
CPU times: user 13.4 s, sys: 482 ms, total: 13.9 s
Wall time: 13.9 s<jupyter_text>Consumed once 😱 Every time you want to reuse the elements in a collection it must be regenerated.<jupyter_code>g = generators(range(10**8))
print(f"First consumption: {sum(g)}")
print(f"Second consumption: {sum(g)}")
g = generators(range(10**8))
g1, g2 = itertools.tee(g, 2)
print(f"First consumption: {sum(g1)}")
print(f"Second consumption: {sum(g2)}")<jupyter_output>First consumption: 4711503365894179
Second consumption: 4711503365894179
{'fraction_non_alphanumeric': 0.13138075313807532, 'fraction_numerical': 0.09288702928870293, 'mean_word_length': 7.191780821917808, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '76387', 'license': 'MIT', 'n_tokens_mistral': 515, 'n_tokens_neox': 433, 'n_words': 126, 'path': 'Lectures/Generators.ipynb', 'repo_name': 'eyaltrabelsi/Monty-Hall-Problem', 'size': '1195'}