avatarBruce Coulter

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1818

Abstract

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

fibonacci = islice(fibonacci_gen(), <span class="hljs-number">10</span>)

<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>

CHALLENGES

My Version of a This and That Challenge

Who doesn’t love a good dare?

Sunset on Cape Cod. © Bruce Coulter Photography

As I’ve traveled the many roads of Medium, I’ve seen any number of writing prompts and challenges. Of the stories I’ve read, they’re all grand, full of humor, cheer, and occasionally sadness.

We’ve all had our share of sad memories and moments, laughs and joys. Today, I offer my version of a this and that challenge. For the faint of heart, it is not rated PG.

Resolution or revolution? If I were Donald Trump, I would resolve to spearhead a revolution to get my orange-hued ass back in the White House, but not take responsibility for it. Fuck. He already did that. Never mind.

Coffee or tea? Let me stop you right there. No tea. Fuck tea unless it’s a Long Island Iced Tea. Drink enough of those fuckers, and you won’t care about Trump. Bartender?

Fish or cut bait? The last time I went fishing was off the coast of Guam in 1977. Some of my fellow jarheads decided renting a boat to go deep-sea fishing would be a good idea. I don’t know if it was. We started drinking the moment we pulled out of port.

Long or short? Is this a size matters question? Do I have to answer it? Can you tell if my answer is coming up a bit short?

Fiction or Non-fiction? This is a tough one. Republicans recently elected a new House speaker who willingly conceded much of his power for no reason other than to wrap his hands around a phallus-like handle and swear in a congressman whose entire past is largely fiction. It’s just a matter of time before “Never” Kevin McCarthy is pushed out of the speaker’s suite and George “Walter Mitty” Santos is dumped in a recall vote. That’s non-fiction I can get behind.

Clap or Follow? To be honest, I had the clap about 40 years ago after a visit to a tea house in the Philippines. Wait. Are we talking about Medium? Damn it!

Funny or Serious? Seriously?

Winter or Summer? Winter. I’m built like a polar bear, and I’m not fond of hot weather. The bonus here is it keeps me out of Florida and away from the chubby guv.

Handwritten or Typed? If you saw my handwriting, you’d be glad I’m typing this article.

Sunrise or Sunset? I’m a photographer, so I’m good with both. (Never thought I’d give a straight answer, did you?)

Airplanes or automobiles? Planes if it’s a must. But I’d drive if there was a bridge from the U.S. to Europe with gas stations and Port-O-Potties every hundred or so miles. I like being in control — and on top.

Fuck this or fuck that? I prefer fuck you. It tends to make people leave me the fuck alone — for a while, at least.

If you’ve read this far, thank you for stopping by. Lay 50 claps on me and comment, if you would please. Cheers!

I accept tips, which go directly to Dining for Hunger, a recognized 501(c)(3) organization that looks to end food insecurity. If you can spare a dollar or two, I’d be grateful.

Like what you read? Check out more of my stories below.

Bouncin And Behavin Blogs
Humor
Satire
Challenge
Writing
Recommended from ReadMedium