#LazyEvaluation#Python 9: When working with lage data, we can chain generators together to create pipeline, each generator in the pipeline takes input from the previous generator, processes it, and passes it along to the next generator.
This is a powerful construct in Python.
#LazyEvaluation#Python 6: Generators can also be used to generate infinite sequences.
See #code#snippet below:
Guess the output here, just remember yield will save the context before returning so variables will also be saved.
#LazyEvaluation#Python 4: So let's see how much memory benefit we get by using lazy evaluation in Python.
Here we are creating normal and lazy objects and then printing their size.
#LazyEvaluation#Python 3: You can get values now, but there is a traceback right ? Exception is generated named StopIteration.
So the object (created by using yield, called generator) generates a StopIteration exception when exhausted.
So this can directly be used loops..
#LazyEvaluation#Python 2: Last #codesnippet has printed result as #Python generator object. So we can say Generators use yield to generate values lazily.
To get real value we can use next() as in below snippet.
#LazyEvaluation#Python 1: yield keyword - suspends function execution by saving all the states and yield (return) to caller. Later resumes when called again, producing a series of values.
Lets see with this #Snippet and guess the output ..
Let's explore lazy evaluation in Python. exprs upfront, storing them in memory to be used as needed. This approach leads to higher memory usage, which can be avoided by using lazy evaluation which produces values sequentially as needed.
Let's learn how to do lazy evaluation in π
Lets have some warmup using #Python. In #pythonprogramming some very useful concepts are used which are showed in below #codesnippet. Can you identify few of them ?
What you see future of #stackoverflow in next 2 to 3 years ? I feel with all kind of copilots and chatGPT wrappers for code complete it is going to be another Nokia soon.
Let me know your thoughts.