a, b = <span class="hljs-number">1</span>, <span class="hljs-number">1</span>
<span class="hljs-comment"># Generate the rest of the sequence</span>
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n):
<span class="hljs-keyword">yield</span> a
a, b = b, a + b
<span class="hljs-comment"># Generate the Fibonacci sequence up to the 10th number</span>
<span class="hljs-keyword">for</span> number <span class="hljs-keyword">in</span> fibonacci(<span class="hljs-number">10</span>):
<span class="hljs-built_in">print</span>(number)</pre></div><p id="580b">And here is an example of a generator expression:</p><div id="2845"><pre><span class="hljs-comment"># Generator expression to generate the Fibonacci sequence</span>
<span class="hljs-keyword">from</span> itertools <span class="hljs-keyword">import</span> islice
<span class="hljs-keyword">def</span> <span class="hljs-title function_">fibonacci_gen</span>():
a, b = <span class="hljs-number">1</span>, <span class="hljs-number">1</span>
<span class="hljs-keyword">while</span> <span class="hljs-literal">True</span>:
<span class="hljs-keyword">yield</span> a
a, b = b, a + b
<span class="hljs-comment"># Generate the Fibonacci sequence up to the 10th number</span>
<span class="hljs-keyword">for</span> number <span class="hljs-keyword">in</span> fibonacci:
<span class="hljs-built_in">print</span>(number)</pre></div><p id="83f6">Few points to note about both:</p><ul><li>Generators are more memory-efficient than lists because they only generate one value at a time, rather than creating an entire sequence of values in memory at once. This makes them useful fo
Options
r generating large sequences of data that you don’t need to access all at once.</li><li>Generator functions are defined using the <code>def</code> keyword, just like any other function. However, instead of using the <code>return</code> keyword to return a value, generator functions use the <code>yield</code> keyword to yield a value. When the generator function is called, it does not execute the function body immediately. Instead, it returns a generator object that can be iterated over to execute the function body one line at a time.</li><li>Generator expressions are similar to list comprehensions, but they return a generator object instead of a list. They are defined using parentheses, and they use the same syntax as list comprehensions, but with a single element on the right-hand side of the expression.</li><li>Both generators and generator expressions are iterable, which means you can use them in a <code>for</code> loop or with the <code>next()</code> function to access their values one at a time.</li><li>You can use the <code>iter()</code> function to create an iterator from a generator or generator expression. You can then use the <code>next()</code> function to retrieve the next value from the generator one at a time.</li></ul><p id="2077"><i>More content at <a href="https://plainenglish.io/"><b>PlainEnglish.io</b></a>.</i></p><p id="de2f"><i>Sign up for our <a href="http://newsletter.plainenglish.io/"><b>free weekly newsletter</b></a>. Follow us on <a href="https://twitter.com/inPlainEngHQ"><b>Twitter</b></a></i>, <a href="https://www.linkedin.com/company/inplainenglish/"><b><i>LinkedIn</i></b></a><i>, <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><b>YouTube</b></a>, and <a href="https://discord.gg/GtDtUAvyhW"><b>Discord</b></a><b>.</b></i></p></article></body>
Welcome back, readers, to this week’s edition of “To 100 and Beyond With Love,” — where I explore some of my favorite reads and support writers in growing their Medium readership.
If you missed the past editions of this weekly review — check them out here:
As is tradition, I supply some musical inspiration each week to accompany this review.
In a throwback to my college years: “Put your records on” and “let your hair down,” you’re “gonna find” a writer you love — “somehow.”
Janine B. “The Last Time”
First up is a poem from writer Janine B. — published in Know Thyself, Heal Thyself, “The Last Time” is a haiku about final interactions.
I love reading and writing poetry and admire those who’ve mastered the art of haiku (as I have not).
Limited to a mere seventeen syllables and three lines, the writer must convey the full scope of emotion most briefly.
Janine does just that in this poem, which serves as a powerful reminder that we never know when “the last time” we embrace another.
Next is another poem from writer Min L. A self-published piece, “A Morning Routine,” is the type of poem that looks at an everyday event and goes deep.
The poet describes her morning beauty routine as “A dab of concealer” and “A swipe of gloss,” but beneath the surface, a conversation exists.
About the things we do to be “beautiful” — the why and how of it.
Min’s closing, “All over again/Monday to Friday,” serves as a reminder that the repetition of a routine can make it an extension of who we are.
MJ Davison “I Just Finished Watching ‘Midnight Mass’ on Netflix”
It’s no secret — I love reviews — writing them and reading them, so I was excited to see this article pop up on my homepage.
Writer MJ Davison reviews the Netflix series Midnight Mass in this article published in Evolve.
A fan of the creators, Mike Flanagan’s, other projects (Hill House/Bly Manor), I binged watched Midnight Mass in October. Still, Davison’s review provided extra insight into Flanagan’s motivation for the project.
Further, she does an amazing job diving deep into the themes and motifs of the show, analyzing the inner workings, and asking thought-provoking questions.
I relished this insight:
We do, by the way, live on an island. It’s a gorgeous, ball of water and land in the middle of a galaxy that is isolated from any outside help. We’re it…Once we allow ourselves to turn on one another…what kind of salvation do we actually deserve?
Eduard Sebastian “Create a Community, Not a Following”
Published in Writer’s Blokke, “Create a Community, Not a Following,” is writer Eduard Sebastian’s argument for writers to take “the road less traveled” on their Medium journey.
Acknowledging the allure of instant gratification, Sebastian counters this approach — challenging the “hack” style articles that promise “quick fixes” to complex issues: depression, anxiety, even building a readership on the platform.
He praises the merits of taking time and putting in the work:
I love writing because of the process of painting the intricate picture in my head through words. I don’t feel the need to try to force myself to do this as efficiently as possible because for me is a creative act. An act of play. When you play you don’t mind the clumsiness, the misses, you only care about having a good time.
Historium “Virtual Art Exhibition: Paintings of Grigory Gurkin”
I love visiting museums — particularly art museums. And, I’m not ashamed to admit that I cried the first time I witnessed Pollock’s “Autumn Rhythm (№30)” in person.
So, I was thrilled when I came across the work of writer Historium who “blogs about exciting historical characters and events.”
This self-published “Virtual Art Exhibition” explores the work of Grigory Gurkin — a “native Altaian painter.”
The article is a rich visual experience, displaying Gurkin’s breathtaking landscapes and “the majestic nature of Altai and the life of its ethnic inhabitants.”
A commentary accompanies each painting, educating readers.