{"id":119965,"date":"2026-07-06T23:07:57","date_gmt":"2026-07-06T17:37:57","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=119965"},"modified":"2026-07-06T23:07:59","modified_gmt":"2026-07-06T17:37:59","slug":"generators-vs-iterators-in-python","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/generators-vs-iterators-in-python\/","title":{"rendered":"Generators vs Iterators in Python: When to Use Which?"},"content":{"rendered":"\n<p>Python offers several ways to process data efficiently, especially when working with large datasets and continuous data streams. Two important concepts that support this are generators and iterators. Both allow programs to handle data one item at a time instead of loading everything into memory, helping improve performance and memory usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR<\/strong> <strong>Summary<\/strong><\/h2>\n\n\n\n<ol>\n<li>An iterator is an object that follows Python&#8217;s iterator protocol by implementing<strong> iter()<\/strong> and <strong>next()<\/strong>.<\/li>\n\n\n\n<li>A generator is an easier way to create an iterator using the yield keyword.<\/li>\n\n\n\n<li>Generators are usually preferred because they need less code and support lazy evaluation.<\/li>\n\n\n\n<li>Custom iterators are helpful when you need more control over the iteration behavior.<\/li>\n\n\n\n<li>Custom iterators are useful for complex state management and reusable functionality.<\/li>\n<\/ol>\n\n\n\n<p>To build practical skills around concepts like generators, iterators, data handling, and performance optimization, learners can explore <strong>HCL GUVI&#8217;s<\/strong> <a href=\"https:\/\/www.guvi.in\/courses\/programming\/python-zero-to-hero\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Generators+vs+Iterators+in+Python%3A+When+to+Use+Which%3F\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Python<\/strong><\/a><strong> Course<\/strong>, which covers fundamental concepts and real-world applications used in modern software development.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Are Iterators in Python?<\/strong><\/h2>\n\n\n\n<p>An <a href=\"https:\/\/www.guvi.in\/hub\/python-tutorial\/iterable-and-iterator\/\" target=\"_blank\" rel=\"noreferrer noopener\">iterator<\/a> is an object that lets you go through a collection one item at a time. Iterators follow Python&#8217;s iterator protocol, which requires two methods:<\/p>\n\n\n\n<ol>\n<li><strong>iter()<\/strong><\/li>\n\n\n\n<li><strong>next()<\/strong><\/li>\n<\/ol>\n\n\n\n<p>The <strong>next()<\/strong> method returns the next value in a sequence. When there are no more values available, Python raises a StopIteration exception.<\/p>\n\n\n\n<p>Many built-in Python objects are iterable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>numbers = [1, 2, 3]<br>iterator = iter(numbers)<br><strong>print<\/strong>(next(iterator))<br><strong>print<\/strong>(next(iterator))<br><strong>print<\/strong>(next(iterator))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output<\/strong><\/h3>\n\n\n\n<p>1<\/p>\n\n\n\n<p>2<\/p>\n\n\n\n<p>3<\/p>\n\n\n\n<p>Whenever you use a for loop in Python, an iterator works in the background.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Are Generators in Python?<\/strong><\/h2>\n\n\n\n<p>A <a href=\"https:\/\/www.guvi.in\/hub\/python-tutorial\/python-generators\/\" target=\"_blank\" rel=\"noreferrer noopener\">generator<\/a> is a special kind of iterator created using the <strong>yield<\/strong> keyword.<\/p>\n\n\n\n<p>Instead of returning all values at once, generators produce values only when asked for them. This approach, known as<strong> lazy evaluation<\/strong>, helps save memory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def count_up_to(limit):<br>&nbsp; current = 1<br>&nbsp; <strong>while<\/strong> current &lt;= limit:<br>&nbsp; &nbsp; &nbsp; <strong>yield<\/strong> current<br>&nbsp; &nbsp; &nbsp; current += 1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Usage<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>for<\/strong> number in count_up_to(5):<br>&nbsp; <strong>print<\/strong>(number)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output<\/strong><\/h3>\n\n\n\n<p>1<\/p>\n\n\n\n<p>2<\/p>\n\n\n\n<p>3<\/p>\n\n\n\n<p>4<\/p>\n\n\n\n<p>5<\/p>\n\n\n\n<p>The yield statement pauses the function and keeps its state. The next time a value is requested, execution resumes from where it stopped.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Iterator vs Generator: Key Differences<\/strong><\/h2>\n\n\n\n<p>Even though generators and iterators are closely related, there are key differences.<\/p>\n\n\n\n<ol>\n<li>Iterators need a class with <strong>iter()<\/strong> and <strong>next()<\/strong> methods, while generators use the yield keyword.<\/li>\n\n\n\n<li>Iterators need manual state management, while generators automatically keep state.<\/li>\n\n\n\n<li>Iterators typically have more boilerplate code, while generators are concise and easier to read.<\/li>\n\n\n\n<li>Both are memory efficient because they process values one at a time.<\/li>\n\n\n\n<li>Generators are generally preferred when simplicity and readability are crucial.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating a Custom Iterator<\/strong><\/h2>\n\n\n\n<p>Suppose you want to create a counter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<p>class Counter:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>&nbsp; def __init__(<strong>self<\/strong>, limit):<br>&nbsp; &nbsp; &nbsp; <strong>self<\/strong>.limit = limit<br>&nbsp; &nbsp; &nbsp; <strong>self<\/strong>.current = 1<br>&nbsp; def __iter__(<strong>self<\/strong>):<br>&nbsp; &nbsp; &nbsp; <strong>return<\/strong> <strong>self<\/strong><br>&nbsp; def __next__(<strong>self<\/strong>):<br>&nbsp; &nbsp; &nbsp; <strong>if<\/strong> <strong>self<\/strong>.current &gt; <strong>self<\/strong>.limit:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise StopIteration<br>&nbsp; &nbsp; &nbsp; value = <strong>self<\/strong>.current<br>&nbsp; &nbsp; &nbsp; <strong>self<\/strong>.current += 1<br>&nbsp; &nbsp; &nbsp; <strong>return<\/strong> value<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Usage<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>counter = Counter(5)<br><strong>for<\/strong> value in counter:<br>&nbsp; <strong>print<\/strong>(value)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output<\/strong><\/h3>\n\n\n\n<p>1<\/p>\n\n\n\n<p>2<\/p>\n\n\n\n<p>3<\/p>\n\n\n\n<p>4<\/p>\n\n\n\n<p>5<\/p>\n\n\n\n<p>This approach works well but requires a significant amount of code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating a Generator<\/strong><\/h2>\n\n\n\n<p>You can achieve the same functionality more easily with a generator.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def counter(limit):<br>&nbsp; current = 1<br>&nbsp; <strong>while<\/strong> current &lt;= limit:<br>&nbsp; &nbsp; &nbsp; <strong>yield<\/strong> current<br>&nbsp; &nbsp; &nbsp; current += 1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Usage<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>for<\/strong> value in counter(5):<br>&nbsp; <strong>print<\/strong>(value)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Output<\/strong><\/h3>\n\n\n\n<p>1<\/p>\n\n\n\n<p>2<\/p>\n\n\n\n<p>3<\/p>\n\n\n\n<p>4<\/p>\n\n\n\n<p>5<\/p>\n\n\n\n<p>In most cases, the generator version is easier to write and maintain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Memory and Performance Comparison<\/strong><\/h2>\n\n\n\n<p>One of the main advantages of generators is memory efficiency.<\/p>\n\n\n\n<p>Consider creating one million numbers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Using a List<\/strong><\/h3>\n\n\n\n<p>numbers = [x for x in range(1000000)]<\/p>\n\n\n\n<p>All values are stored in memory immediately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Using a Generator Expression<\/strong><\/h3>\n\n\n\n<p>numbers = (x for x in range(1000000))<\/p>\n\n\n\n<p>Values are created only when needed.<\/p>\n\n\n\n<p>This makes generators particularly useful for:<\/p>\n\n\n\n<ol>\n<li>Large datasets<\/li>\n\n\n\n<li>Data pipelines<\/li>\n\n\n\n<li>Log processing<\/li>\n\n\n\n<li>Machine learning workflows<\/li>\n\n\n\n<li>Streaming applications<\/li>\n<\/ol>\n\n\n\n<p>When dealing with large amounts of data, generators can greatly reduce memory usage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>When to Use Iterators<\/strong><\/h2>\n\n\n\n<p>Choose a custom iterator when:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. You Need Complex State Management<\/strong><\/h3>\n\n\n\n<p>Some applications need to track multiple internal states.<\/p>\n\n\n\n<p>Examples include:<\/p>\n\n\n\n<ol>\n<li>Workflow engines<\/li>\n\n\n\n<li>Game systems<\/li>\n\n\n\n<li>Navigation systems<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. You Need Additional Methods<\/strong><\/h3>\n\n\n\n<p>Iterator classes can provide extra functionality.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<p>counter.reset()<\/p>\n\n\n\n<p>counter.pause()<\/p>\n\n\n\n<p>counter.resume()<\/p>\n\n\n\n<p>A generator function cannot easily offer these features.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. You&#8217;re Building Reusable Components<\/strong><\/h3>\n\n\n\n<p><a href=\"https:\/\/www.guvi.in\/blog\/python-libraries-explained\/\">Libraries<\/a> and frameworks often use iterator classes for greater flexibility and control.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>When to Use Generators<\/strong><\/h2>\n\n\n\n<p>Choose generators when:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Processing Large Files<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def read_large_file(filename):<br>&nbsp; with open(filename) <strong>as<\/strong> file:<br>&nbsp; &nbsp; &nbsp; <strong>for<\/strong> line in file:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong>yield<\/strong> line<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Only one line is loaded into memory at a time. This makes generators particularly useful when working with large files and <a href=\"https:\/\/www.guvi.in\/hub\/python-tutorial\/file-handling\/\" target=\"_blank\" rel=\"noreferrer noopener\">file handling operations <\/a>where loading the entire file into memory may not be practical.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Working with Data Streams<\/strong><\/h3>\n\n\n\n<p>Generators are commonly used for:<\/p>\n\n\n\n<ol>\n<li>Log processing<\/li>\n\n\n\n<li>Sensor data<\/li>\n\n\n\n<li><a href=\"https:\/\/www.guvi.in\/hub\/network-programming-with-python\/understanding-apis\/\" target=\"_blank\" rel=\"noreferrer noopener\">API <\/a>responses<\/li>\n\n\n\n<li>Event streams<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Building Data Pipelines<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def filter_even(numbers):<br>&nbsp; <strong>for<\/strong> num in numbers:<br>&nbsp; &nbsp; &nbsp; <strong>if<\/strong> num % 2 == 0:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong>yield<\/strong> num<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Generators can be chained together efficiently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Writing Cleaner Code<\/strong><\/h3>\n\n\n\n<p>Often, a generator can replace lots of lines of iterator boilerplate while remaining easy to understand.<\/p>\n\n\n\n<p>To gain practical experience with generators and other essential programming concepts, learners can explore <strong>HCL GUVI&#8217;s <\/strong><a href=\"https:\/\/www.guvi.in\/courses\/programming\/python-zero-to-hero\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Generators+vs+Iterators+in+Python%3A+When+to+Use+Which%3F\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Python<\/strong><\/a><strong> Course<\/strong>, which includes hands-on projects and real-world applications.\u00a0<\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\">\n\n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong>\n  <br \/><br \/>\n\n  <strong style=\"color: #FFFFFF;\">Python<\/strong> supports <strong style=\"color: #FFFFFF;\">generator expressions<\/strong>, a concise way to create generators that produce values <strong style=\"color: #FFFFFF;\">lazily<\/strong>\u2014one item at a time instead of generating an entire collection in memory. This makes them highly memory-efficient for processing large datasets, streams, or files, and they are commonly used in data processing pipelines, iterations, and functional programming patterns.\n\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<p>squares = (x * x for x in range(10))<\/p>\n\n\n\n<p>Generator expressions look like list comprehensions but generate values only when needed. This makes them more memory efficient for large datasets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes to Avoid<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Reusing an Exhausted Generator<\/strong><\/h3>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>gen = (x <strong>for<\/strong> x in range(5))<br><strong>list<\/strong>(gen)<br><strong>list<\/strong>(gen)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The second call returns no values because the generator has already been exhausted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Using Lists for Massive Datasets<\/strong><\/h3>\n\n\n\n<p>Avoid creating large lists when a generator can process data lazily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Building Custom Iterators Unnecessarily<\/strong><\/h3>\n\n\n\n<p>Many developers create iterator classes when a generator would solve the problem with less code and better readability.<\/p>\n\n\n\n<p>Want to strengthen your Python skills beyond generators and iterators?<\/p>\n\n\n\n<p>Download <strong>HCL GUVI&#8217;s <\/strong><a href=\"https:\/\/www.guvi.in\/mlp\/python-ebook?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Generators+vs+Iterators+in+Python%3A+When+to+Use+Which%3F\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Python Programming<\/strong><\/a> <strong>eBook<\/strong> to learn about functions, object-oriented programming, file handling, modules, and advanced Python concepts through practical examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Best Practices<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Prefer Generators by Default<\/strong><\/h3>\n\n\n\n<p>If your goal is to produce values one at a time, generators are usually the best option.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Use Iterators for Advanced Behavior<\/strong><\/h3>\n\n\n\n<p>Choose custom iterators when you need precise control over state management.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Use Generator Expressions<\/strong><\/h3>\n\n\n\n<p>For simple transformations:<\/p>\n\n\n\n<p>squares = (x * x for x in range(100))<\/p>\n\n\n\n<p>This is often cleaner than creating a full generator function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Stream Data Whenever Possible<\/strong><\/h3>\n\n\n\n<p>For APIs, files, and large datasets, generators help save memory and improve scalability.<\/p>\n\n\n\n<p>As you continue building Python skills, learning <a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-the-official-python-documentation\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to use the official Python documentation<\/a> can make it easier to explore concepts like generators, iterators, and other advanced language features independently.\u00a0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Both generators and iterators play an important role in efficient data processing in Python, but they are designed for different use cases. Generators offer a simple and memory-efficient way to produce values on demand, while custom iterators provide greater control over iteration behavior and state management.&nbsp;<\/p>\n\n\n\n<p>Understanding when to use each approach can help developers write cleaner, more scalable, and more efficient Python applications. As a general rule, start with generators for simplicity and use custom iterators only when additional control is required.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1782935341116\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>1. What is the main difference between generators and iterators in Python?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Iterators are objects that implement <strong>iter()<\/strong> and <strong>next()<\/strong>, while generators are an easier way to create iterators using the yield keyword.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782935346075\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>2. Are generators faster than iterators?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Performance is usually similar. The main advantage of generators is cleaner code and automatic state management.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782935354703\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>3. Why are generators memory efficient?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Generators produce values only when requested instead of storing all values in memory at once.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782935366292\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>4. Can a generator be iterated multiple times?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No. Once a generator is exhausted, it must be recreated before being used again.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782935380974\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>5. Should I use generators or iterators in modern Python applications?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>In most cases, generators are recommended because they are concise, readable, and save memory.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782935389523\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>6. What is the difference between an iterable and an iterator in Python?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>An iterable is an object that can be traversed, like a list or tuple. An iterator keeps track of its current position and returns values one at a time.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1782935401543\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>7. What is a generator expression in Python?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A generator expression is a compact way to create generators using syntax similar to list comprehensions while generating values lazily.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Python offers several ways to process data efficiently, especially when working with large datasets and continuous data streams. Two important concepts that support this are generators and iterators. Both allow programs to handle data one item at a time instead of loading everything into memory, helping improve performance and memory usage. TL;DR Summary To build [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":121411,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[717],"tags":[],"views":"23","authorinfo":{"name":"Vishalini Devarajan","url":"https:\/\/www.guvi.in\/blog\/author\/vishalini\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/07\/generators-vs-iterators-in-python-300x118.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/119965"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=119965"}],"version-history":[{"count":2,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/119965\/revisions"}],"predecessor-version":[{"id":121412,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/119965\/revisions\/121412"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/121411"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=119965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=119965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=119965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}