This is a premium lesson. You can see the shape of every card — unlock to read them.
Unlock
ADVANCED LIST PROCESSING - IT……
Premium
This card is part of the premium lesson.
Unlock
Advanced List Processing என்பது list அல்லது மற்ற iterable collections-ல் ……
Premium
This card is part of the premium lesson.
Unlock
1. Iterator 2. Generator…
Premium
This card is part of the premium lesson.
Unlock
Simple idea: List ↓ One item at a time process செய்ய ↓ Itera……
Premium
This card is part of the premium lesson.
Unlock
Suppose: numbers = [10, 20, 30, 40] Normal list already contains all values: 10 20 30 40 ஒரு for loop: for x ……
Premium
This card is part of the premium lesson.
Unlock
Iterable ↓ iter() ↓ Iterator ↓ next() ↓ One value ↓ next() ↓ Next value ↓ ... ↓ StopIteration Generat……
Premium
This card is part of the premium lesson.
Unlock
Iterator என்பது collection-ல் உள்ள elements-ஐ one by one ……
Premium
This card is part of the premium lesson.
Unlock
Example
numbers = [10, 20, 30] இந்த list i……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Iterable vs iterator
இந்த இரண்டு terms மிகவும் important. Iterable L……
Premium
This card is part of the premium lesson.
Unlock
Example
numbers = [10, 20, 30] numbers is iterable.……
Premium
This card is part of the premium lesson.
Unlock
it is iterator. Memory: Iterable ……
Premium
This card is part of the premium lesson.
Unlock
Next value get: next(iterator……
Premium
This card is part of the premium lesson.
Unlock
numbers = [10, 20, 30] List created. it = iter(numbers) Python list-க்கான iterator object create செய்கிறது……
Premium
This card is part of the premium lesson.
Unlock
Dry Run
numbers = [10, 20, 30]
Stopiteration
Suppose: numbers = [10, 20] it = iter(numbers) print(next(it)) print(……
Premium
This card is part of the premium lesson.
Unlock
StopIteration means: Iterator has no more values. It i……
Premium
This card is part of the premium lesson.
Unlock
For loop and iterator
When writing: for x in [10, 20, 30]: print(x) Python conceptually does something similar to: it =……
Premium
This card is part of the premium lesson.
Unlock
Important concept
for loop = automatic iterator handling You ……
Premium
This card is part of the premium lesson.
Unlock
Iterator with string
String is iterable. text = "ABC" it =……
Premium
This card is part of the premium lesson.
Unlock
Iterator with tuple
data = (100, 200, 300) it = i……
Premium
This card is part of the premium lesson.
Unlock
Iterator with dictionary
Dictionary iteration gives keys by default. student = { "name": "Arun", "ma……
Premium
This card is part of the premium lesson.
Unlock
Iterator is stateful
Iterator remembers where it s……
Premium
This card is part of the premium lesson.
Unlock
If later
It does not restart from 1. T……
Premium
This card is part of the premium lesson.
Unlock
Iterator exhaustion
Once an iterator is fully consumed, it cannot automat……
Premium
This card is part of the premium lesson.
Unlock
Why second empty list? Iterat……
Premium
This card is part of the premium lesson.
Unlock
New iterator required
To start again: it = iter(num……
Premium
This card is part of the premium lesson.
Unlock
Iterator protocol
Python iterator protocol mainly requires: __iter__() ……
Premium
This card is part of the premium lesson.
Unlock
Custom iterator
We can create our own iterator class. class Numbers: def __in……
Premium
This card is part of the premium lesson.
Unlock
Custom iterator line explanation
self.current = 1 Starting value. def __iter__(self): return se……
Premium
This card is part of the premium lesson.
Unlock
Generator என்பது values-ஐ ஒரே நேரத்தில் எல்லாம் create/store செய்யாமல், தேவைப்படும் போது……
Premium
This card is part of the premium lesson.
Unlock
Normal function: def test(): return 10 Function returns value and ends. Generator function: def test(): yiel……
Premium
This card is part of the premium lesson.
Unlock
Usage
Premium
This card is part of the premium lesson.
Unlock
Calling: g = numbers() does not execute the complete functi……
Premium
This card is part of the premium lesson.
Unlock
Dry Run
Generator dry run
Yield
yield is the heart of generat……
Premium
This card is part of the premium lesson.
Unlock
return → sends value → function ends yield……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Return vs yield
Normal function: def test(): ……
Premium
This card is part of the premium lesson.
Unlock
Because function ends after f……
Premium
This card is part of the premium lesson.
Unlock
Output through loop: 10 20…
Premium
This card is part of the premium lesson.
Unlock
Generator with for loop
def numbers(): yield 1 yield ……
Premium
This card is part of the premium lesson.
Unlock
for automatically calls gener……
Premium
This card is part of the premium lesson.
Unlock
Generator using loop
Better real example: def generate_numbers(n): ……
Premium
This card is part of the premium lesson.
Unlock
def generate_numbers(n): Generator function. for i ……
Premium
This card is part of the premium lesson.
Unlock
Generator does not create full list: [……
Premium
This card is part of the premium lesson.
Unlock
Generator for squares
Normal list processing: squares = []……
Premium
This card is part of the premium lesson.
Unlock
All values stored in list. Ge……
Premium
This card is part of the premium lesson.
Unlock
Values produced one-by-one.…
Premium
This card is part of the premium lesson.
Unlock
Comparison
List vs generator memory
Suppose: numbers = [x*x for x in range(1000000)] This creates and stores all one million values. Memory usage……
Premium
This card is part of the premium lesson.
Unlock
Lazy evaluation
Lazy evaluation means: Do not……
Premium
This card is part of the premium lesson.
Unlock
Example
At this stage, all squares are not necessarily mat……
Premium
This card is part of the premium lesson.
Unlock
Generator expression
Like list comprehension: [x*x for x in range(5)] Generator expres……
Premium
This card is part of the premium lesson.
Unlock
Program generator expression
Comparison
List comprehension vs generator expression
List comprehension: result = ……
Premium
This card is part of the premium lesson.
Unlock
Result
Type
Generator expression
Type
Premium
This card is part of the premium lesson.
Unlock
Generator exhaustion
Generators are iterators. Once consumed, they……
Premium
This card is part of the premium lesson.
Unlock
Because first list(g) consume……
Premium
This card is part of the premium lesson.
Unlock
Generator state
Generator remembers local var……
Premium
This card is part of the premium lesson.
Unlock
Example
yield x x += 1 yield x x += 1……
Premium
This card is part of the premium lesson.
Unlock
x value is remembered between……
Premium
This card is part of the premium lesson.
Unlock
Generator with condition
def even_numbers(n): for i in range(1, n ……
Premium
This card is part of the premium lesson.
Unlock
Generator for list processing
Suppose list: numbers = [1, 2, 3, 4, 5] We need only squares of ev……
Premium
This card is part of the premium lesson.
Unlock
Processing: 1 → odd → ignore 2 → e……
Premium
This card is part of the premium lesson.
Unlock
Chained processing
Generator expressions useful for data pipelines. numbers = range(1,……
Premium
This card is part of the premium lesson.
Unlock
Flow: 1..10 ↓ Filter even ↓ 2,4,6,8,1……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Iterator vs generator
Iterator General object that produces one item at a time. Can be created using: iter() or……
Premium
This card is part of the premium lesson.
Unlock
Every generator is an iterator.……
Premium
This card is part of the premium lesson.
Unlock
Example
This is iterator. But it is n……
Premium
This card is part of the premium lesson.
Unlock
Iterable iterator generator relation
Iterable | | iter() ↓ Iterator | | next() ↓ Values Generator: Generator ↓ ……
Premium
This card is part of the premium lesson.
Unlock
Important difference list and iterator
List: numbers = [10, 20, 30] Can be traversed repeatedly: for x in numbers: print(x) for x in n……
Premium
This card is part of the premium lesson.
Unlock
Comparison
List vs generator
Generator no indexing
List: numbers = [10, 20, 30] ……
Premium
This card is part of the premium lesson.
Unlock
Generator: g = (x for x in [1……
Premium
This card is part of the premium lesson.
Unlock
Why? Generator values are pro……
Premium
This card is part of the premium lesson.
Unlock
Generator no len
This: g = (x for x in range(5)) print(len(g)) causes error. Generators do n……
Premium
This card is part of the premium lesson.
Unlock
Next with default
next() can accept a default v……
Premium
This card is part of the premium lesson.
Unlock
Example
This avoids visible StopItera……
Premium
This card is part of the premium lesson.
Unlock
Why use iterators
Iterators useful when: Large collection process செய்ய One item at a time traverse செய்ய Memory usage reduce ……
Premium
This card is part of the premium lesson.
Unlock
Why use generators
Generators useful when: Large number of values Infinit……
Premium
This card is part of the premium lesson.
Unlock
Infinite generator
Generators can represent infi……
Premium
This card is part of the premium lesson.
Unlock
Example
Usage carefully
Generator doesn't need to create ……
Premium
This card is part of the premium lesson.
Unlock
Fibonacci generator
Important advanced example: def fibonacci(n): a = 0……
Premium
This card is part of the premium lesson.
Unlock
Dry Run
Fibonacci dry run
Memory efficiency
Consider: numbers = [x for x in range(10000000)] Python must maintain millions of integer references in a lis……
Premium
This card is part of the premium lesson.
Unlock
Comparison
Eager vs lazy
Eager Evaluation [x*x for x in range(5)] Immediately calculates: ……
Premium
This card is part of the premium lesson.
Unlock
Example
next(g) one item at a time.…
Premium
This card is part of the premium lesson.
Unlock
Common error 1
Calling next() directly on li……
Premium
This card is part of the premium lesson.
Unlock
Error
TypeError Because list is iterable but no……
Premium
This card is part of the premium lesson.
Unlock
Common error 2
Confusing return and yield. Wrong generator understanding: def numb……
Premium
This card is part of the premium lesson.
Unlock
Common error 3
Trying to reuse exhausted generator……
Premium
This card is part of the premium lesson.
Unlock
Generator already consumed.…
Premium
This card is part of the premium lesson.
Unlock
Common error 4
Trying indexing: g = (x for x……
Premium
This card is part of the premium lesson.
Unlock
Error.
Generators are sequential, no……
Premium
This card is part of the premium lesson.
Unlock
Common error 5
Thinking generator expression is tuple: x = (n*n for n……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
1. Iterator gives one item at a time. 2. Created using iter(). 3. next() retriev……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
1. Generator is a special iterator. 2. Uses yield. 3. Produces values lazily. 4. M……
Premium
This card is part of the premium lesson.
Unlock
For iterator: ITERATOR = ITER + NEXT iter() ↓ ……
Premium
This card is part of the premium lesson.
Unlock
return → END yield → PAUSE Most important……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Trb point 2
What does next() do? It retri……
Premium
This card is part of the premium lesson.
Unlock
Trb point 3
What happens after all iterat……
Premium
This card is part of the premium lesson.
Unlock
Trb point 4
Which keyword creates a gener……
Premium
This card is part of the premium lesson.
Unlock
Which is a generator expressi……
Premium
This card is part of the premium lesson.
Unlock
Trb point 6
x = [1, 2, 3] y = iter(x) pri……
Premium
This card is part of the premium lesson.
Unlock
Trb point 7
What is output? g = (x for x ……
Premium
This card is part of the premium lesson.
Unlock
Trb point 8
What is the fundamental difference between return and yi……
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Trb point 10
Every iterator is a generator. False Correct: Ever……
Premium
This card is part of the premium lesson.
Unlock
Interview point 1
Why are generators memory efficient? Because generator does not store the……
Premium
This card is part of the premium lesson.
Unlock
Interview point 2
Difference between iterable a……
Premium
This card is part of the premium lesson.
Unlock
Example
[1, 2, 3] Iterator: Can directl……
Premium
This card is part of the premium lesson.
Unlock
Interview point 3
Why can a list be reused but a generator often cannot? A list stores values. ……
Premium
This card is part of the premium lesson.
Unlock
Interview point 4
Is range() a generator? No. range() is an iterable se……
Premium
This card is part of the premium lesson.
Unlock
Example
Which function converts an it……
Premium
This card is part of the premium lesson.
Unlock
Which function retrieves the ……
Premium
This card is part of the premium lesson.
Unlock
When an iterator is exhausted……
Premium
This card is part of the premium lesson.
Unlock
Which keyword is used in gene……
Premium
This card is part of the premium lesson.
Unlock
What is the output? a = [10, ……
Premium
This card is part of the premium lesson.
Unlock
Which uses lazy evaluation?…
Premium
This card is part of the premium lesson.
Unlock
What is the type? x = (n*n fo……
Premium
This card is part of the premium lesson.
Unlock
Which statement is correct?…
Premium
This card is part of the premium lesson.
Unlock
Premium
This card is part of the premium lesson.
Unlock
Generator values are normally……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 1
Predict: a = [5, 10, 15] it = i……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 2
Predict: def test(): yield 10……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 3
Predict: g = (x+1 for x in ra……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 4
Predict: g = (x for x in range(3)……
Premium
This card is part of the premium lesson.
Unlock
Practice
Practice 5
Predict: def even(): for x in range(1, 7……
Premium
This card is part of the premium lesson.
Unlock
Iterator An iterator is an object that provides elements one at a time. numbers = [10, 20, 30] it = iter(numb……
Premium
This card is part of the premium lesson.
Unlock
Short description
Iterator = Collection-ல் இருந்து values-ஐ one-by-one access செய்யும் object. Generator = Values-ஐ memory-ல் எ……
Premium
This card is part of the premium lesson.
Unlock