🤔 Python generators

What are they? How to use them?

#Python

🧵Let's find out 👇

1️⃣ Python generators are lazy iterators delivering the next value when their .next() is called.

They are created by using the yield keyword

next() can be called explicitly or implicitly inside for loop

They can be finite or infinite
2️⃣ yield - where a value is sent back to the caller, but the function doesn’t exit afterward as with the return statement

The state of function is remembered.

For example, the number is incremented and sent back from yield at the consecutive call next()
3️⃣ Generator stores only the current state of the function - it generates next element on next() call and forgets the previous one -> it saves memory

For example, we don't need to store 1mio elements in memory to do something with each element
4️⃣ When you call a generator function generator object is returned - it's not executed yet

It executes only when next() is called

For example, that's why Exception is raised only on the next() call
5️⃣ When the generator goes out of elements it raises StopIteration exception
6️⃣ You can also create a class that behaves like a generator - it needs implemented methods:

- __iter__ -> to enable iteration
- __next__ -> to enable next element access
7️⃣ You can also create a generator with one-liner expression similar to list comprehension
8️⃣ You can read more:

https://t.co/mXp7L8l2Ai

More from Machine learning

Thanks for this incredibly helpful analysis @dgurdasani1

Two questions. 1/ Does this summarise the AZ published data :
The plan is to extend the time interval for all age groups despite it being largely untested on the over 55yrs, although the full data is not yet published


Do we have the actual numbers of over 55yr olds given a 2nd dose at c12 weeks and the accompanying efficacy data?

Not to mention the efficacy data of the full first dose over that same period?

I’d quite like to know whether I am to be a guinea pig & the ongoing risks to manage

You attached photos of excerpts from a paper. Could you attach the link?

Re Pfizer. As I understand it the most efficacious interval for dosing was investigated at the start of the trial.


Here’s the link to the

I’ve got to say that this way of making and announcing decisions is not inspiring confidence in me and I am very pro vaccination as a matter of principle, not least because my brother caught polio before vaccinations available.
With hard work and determination, anyone can learn to code.

Here’s a list of my favorites resources if you’re learning to code in 2021.

👇

1. freeCodeCamp.

I’d suggest picking one of the projects in the curriculum to tackle and then completing the lessons on syntax when you get stuck. This way you know *why* you’re learning what you’re learning, and you're building things

2.
https://t.co/7XC50GlIaa is a hidden gem. Things I love about it:

1) You can see the most upvoted solutions so you can read really good code

2) You can ask questions in the discussion section if you're stuck, and people often answer. Free

3. https://t.co/V9gcXqqLN6 and https://t.co/KbEYGL21iE

On stackoverflow you can find answers to almost every problem you encounter. On GitHub you can read so much great code. You can build so much just from using these two resources and a blank text editor.

4. https://t.co/xX2J00fSrT @eggheadio specifically for frontend dev.

Their tutorials are designed to maximize your time, so you never feel overwhelmed by a 14-hour course. Also, the amount of prep they put into making great courses is unlike any other online course I've seen.

You May Also Like

Rig Ved 1.36.7

To do a Namaskaar or bow before someone means that you are humble or without pride and ego. This means that we politely bow before you since you are better than me. Pranipaat(प्राणीपात) also means the same that we respect you without any vanity.

1/9


Surrendering False pride is Namaskaar. Even in devotion or bhakti we say the same thing. We want to convey to Ishwar that we have nothing to offer but we leave all our pride and offer you ourselves without any pride in our body. You destroy all our evil karma.

2/9

We bow before you so that you assimilate us and make us that capable. Destruction of our evils and surrender is Namaskaar. Therefore we pray same thing before and after any big rituals.

3/9

तं घे॑मि॒त्था न॑म॒स्विन॒ उप॑ स्व॒राज॑मासते ।
होत्रा॑भिर॒ग्निं मनु॑षः॒ समिं॑धते तिति॒र्वांसो॒ अति॒ स्रिधः॑॥

Translation :

नमस्विनः - To bow.

स्वराजम् - Self illuminating.

तम् - His.

घ ईम् - Yours.

इत्था - This way.

उप - Upaasana.

आसते - To do.

स्त्रिधः - For enemies.

4/9

अति तितिर्वांसः - To defeat fast.

मनुषः - Yajman.

होत्राभिः - In seven numbers.

अग्निम् - Agnidev.

समिन्धते - Illuminated on all sides.

Explanation : Yajmans bow(do Namaskaar) before self illuminating Agnidev by making the offerings of Havi.

5/9