<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Satyajeet on Medium]]></title>
        <description><![CDATA[Stories by Satyajeet on Medium]]></description>
        <link>https://medium.com/@satyajeethore5685?source=rss-82f0158b70d8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Satyajeet on Medium</title>
            <link>https://medium.com/@satyajeethore5685?source=rss-82f0158b70d8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 22:55:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@satyajeethore5685/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Python Iterators: A Simple Guide with Examples ]]></title>
            <link>https://medium.com/@satyajeethore5685/python-iterators-a-simple-guide-with-examples-f37d24e502de?source=rss-82f0158b70d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f37d24e502de</guid>
            <dc:creator><![CDATA[Satyajeet]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 05:24:04 GMT</pubDate>
            <atom:updated>2026-09-08T05:24:04.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Dj8tsXvZHGVAOIShk-hpA.webp" /></figure><p>If you use Python for loops, you are already using <strong>iterators</strong>—even if you don&#39;t realize it.</p><p>Understanding iterators helps you understand how Python processes collections, generators, and large amounts of data efficiently.</p><h3>What Is an Iterator?</h3><p>An <strong>iterator</strong> is an object that allows you to access elements one at a time.</p><p>Python provides two important functions:</p><ul><li>iter() — creates an iterator</li><li>next() — gets the next item</li></ul><h3>Example</h3><pre>numbers = [10, 20, 30]</pre><pre>iterator = iter(numbers)</pre><pre>print(next(iterator))<br>print(next(iterator))<br>print(next(iterator))</pre><h3>Output</h3><pre>10<br>20<br>30</pre><p>When there are no more elements, Python raises StopIteration.</p><pre>print(next(iterator))</pre><pre>StopIteration</pre><h3>Iterable vs Iterator</h3><p>These two terms are easy to confuse.</p><p><strong>Iterable:</strong> An object that can be iterated over, such as a list, tuple, or string.</p><p><strong>Iterator:</strong> An object that produces the next value using next().</p><pre>Iterable<br>   ↓<br>iter()<br>   ↓<br>Iterator<br>   ↓<br>next()<br>   ↓<br>Value</pre><p>For example:</p><pre>numbers = [1, 2, 3]</pre><pre>iterator = iter(numbers)</pre><pre>print(next(iterator))  # 1<br>print(next(iterator))  # 2</pre><h3>How Does a for Loop Work?</h3><p>When you write:</p><pre>numbers = [1, 2, 3]</pre><pre>for number in numbers:<br>    print(number)</pre><p>Python uses an iterator behind the scenes to get each value.</p><p>Conceptually, it works like this:</p><pre>iterator = iter(numbers)</pre><pre>while True:<br>    try:<br>        number = next(iterator)<br>        print(number)<br>    except StopIteration:<br>        break</pre><p>This is why understanding iter() and next() helps you understand Python loops better.</p><h3>Creating Your Own Iterator</h3><p>We can create a custom iterator using __iter__() and __next__().</p><pre>class Counter:<br>    def __init__(self, limit):<br>        self.current = 1<br>        self.limit = limit</pre><pre>    def __iter__(self):<br>        return self</pre><pre>    def __next__(self):<br>        if self.current &gt; self.limit:<br>            raise StopIteration</pre><pre>        value = self.current<br>        self.current += 1<br>        return value</pre><p>Now we can use it:</p><pre>counter = Counter(3)</pre><pre>for number in counter:<br>    print(number)</pre><p>Output:</p><pre>1<br>2<br>3</pre><h3>Why Are Iterators Useful?</h3><p>Iterators are especially useful when working with <strong>large amounts of data</strong> because values can be processed one at a time instead of loading everything into memory at once.</p><p>They are commonly used with:</p><ul><li>Large files</li><li>Data processing</li><li>Database results</li><li>Generators</li><li>Data pipelines</li></ul><h3>Iterator vs Generator</h3><p>A <strong>generator</strong> is a simpler way to create an iterator.</p><pre>def count():<br>    for number in range(1, 4):<br>        yield number</pre><pre>for number in count():<br>    print(number)</pre><p>Output:</p><pre>1<br>2<br>3</pre><p>The yield keyword allows Python to produce values one at a time.</p><h3>Conclusion</h3><p>Python iterators are simple once you understand the basic idea:</p><pre>iter()  →  Create iterator<br>next()  →  Get next value<br>StopIteration  →  End of iteration</pre><p>The next time you write a for loop, remember that <strong>an iterator is working behind the scenes</strong>.</p><p>Understanding iterators is also a great foundation for learning <strong>generators, </strong><strong>yield, and lazy evaluation</strong>.</p><p>Happy Coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f37d24e502de" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>