<jupyter_start><jupyter_text>Item 9 Consider Generator Expressions for Large Comprehensions Issue:* It creates a whole new copy which could make your memory full.* If the file, you read in, is huge or even a never-ending network socket this could get problematic.Use generators to solve this issue!* You can build a generator using the same expression but using () instead of [].<jupyter_code>a = [1 ,2 ,3]
generator = (b for b in a)
print(generator.__next__())
print(next(generator))<jupyter_output>1
2
{'fraction_non_alphanumeric': 0.07952286282306163, 'fraction_numerical': 0.011928429423459244, 'mean_word_length': 5.461538461538462, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '504581', 'license': 'MIT', 'n_tokens_mistral': 146, 'n_tokens_neox': 142, 'n_words': 70, 'path': 'notes/Chapter_1:_Pythonic_Thinking/Item 9 Consider Generator Expressions for Large Comprehensions.ipynb', 'repo_name': 'johannstruongle/effective_python', 'size': '503'}