SlideShare a Scribd company logo
1 of 7
Download to read offline
APTUZ
TECHNOLOGY
SOLUTIONS
GENERATORS
IN PYTHON
H T T P S : / / W W W . A P T U Z . C O M /
INTRODUCTION TO GENERATORS
Generators are special Python functions that use the "yield"
keyword.
They're not like regular functions; they have a superpower!
What Are Generators?
Generators allow pausing and resuming their execution.
This unique feature opens the door to efficient memory
management.
Python's Hidden Magic
Generators allow pausing and resuming their execution.
This unique feature opens the door to efficient memory
management.
Python's Hidden Magic
HOW GENERATORS
WORK
Generators can pause and resume their execution.
The "Yield" Keyword:
Execution of a generator function progresses
until it encounters a "yield" keyword.
At that point, the function's state is frozen, and
local variables are stored in memory.
When the generator is called again (e.g., in a for
loop or using "next"), it continues from where it
left off.
This process can continue until the generator is
exhausted.
Resuming Execution:
When dataset size exceeds
memory capacity.
Streaming data directly from
a source to save memory.
Perfect for big data and real-
time analytics.
Handling Large Datasets Efficient Data Processing Infinite Sequences
WHERE GENERATORS SHINE
Process data as it's
generated, reducing memory
footprint.
Ideal for log parsing, sensor
data analysis, and more.
Lazy evaluation: Compute
values only when needed.
Create sequences without
predefined endpoints.
Infinite iterators for
continuous data generation.
Examples include number
series, random data, and
more.
Traditionally, we would create a list
of numbers up to 'n', which could
occupy the entire system memory
space.
This approach is impractical when
dealing with massive numbers, as it
consumes excessive memory
resources.
Conventional
Approach
The Generator
Solution:
CODE EXAMPLE
Imagine the task of printing the squares of numbers from 1 up to an extremely
large number, say 200,000,000.
01
Generators excel at handling large datasets without consuming
excessive memory. They load data as needed, making them ideal
for big data processing.
Memory Efficiency
02
Lazy evaluation allows generators to process data efficiently,
especially when dealing with streams or sequences. No need to
calculate everything upfront.
Efficient Processing
03
Generators embody Python's philosophy of code readability and
simplicity. They lead to cleaner, more elegant code that's easy to
maintain.
Pythonic Elegance
BENEFITS OF GENERATORS
https://www.aptuz.com/
info@aptuz.com
4th Floor, RAM SVR, Madhapur,
HITEC City, Hyderabad -
500081
+(91)-9491754728
THANK YOU

More Related Content

Similar to Generators in Python.pdf

Classifications of computer by bikrant roy
Classifications of computer by bikrant royClassifications of computer by bikrant roy
Classifications of computer by bikrant royRoyB
 
Classification of computer
Classification of computerClassification of computer
Classification of computermaaz hussain
 
Classification of computer 2
Classification of computer 2Classification of computer 2
Classification of computer 2tio_arkarna
 
CA UNIT I PPT.ppt
CA UNIT I PPT.pptCA UNIT I PPT.ppt
CA UNIT I PPT.pptRAJESH S
 
Introduction to computer_system (for MBM first semester, BBA first semester, ...
Introduction to computer_system (for MBM first semester, BBA first semester, ...Introduction to computer_system (for MBM first semester, BBA first semester, ...
Introduction to computer_system (for MBM first semester, BBA first semester, ...RajThakuri
 
Basic of python for data analysis
Basic of python for data analysisBasic of python for data analysis
Basic of python for data analysisPramod Toraskar
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded SystemsSudhanshu Janwadkar
 
Basic of computers
Basic of computersBasic of computers
Basic of computersSanthi thi
 
Classification of computer_system
Classification of computer_systemClassification of computer_system
Classification of computer_systemRajThakuri
 
Chapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPUChapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPUaskme
 
Big Data Real Time Analytics - A Facebook Case Study
Big Data Real Time Analytics - A Facebook Case StudyBig Data Real Time Analytics - A Facebook Case Study
Big Data Real Time Analytics - A Facebook Case StudyNati Shalom
 

Similar to Generators in Python.pdf (20)

Classifications of computer by bikrant roy
Classifications of computer by bikrant royClassifications of computer by bikrant roy
Classifications of computer by bikrant roy
 
Classification of computer
Classification of computerClassification of computer
Classification of computer
 
Classification of computer 2
Classification of computer 2Classification of computer 2
Classification of computer 2
 
Big data no company
Big data   no companyBig data   no company
Big data no company
 
PyTables
PyTablesPyTables
PyTables
 
Large Data Analyze With PyTables
Large Data Analyze With PyTablesLarge Data Analyze With PyTables
Large Data Analyze With PyTables
 
PyTables
PyTablesPyTables
PyTables
 
Py tables
Py tablesPy tables
Py tables
 
Processors
ProcessorsProcessors
Processors
 
CA UNIT I PPT.ppt
CA UNIT I PPT.pptCA UNIT I PPT.ppt
CA UNIT I PPT.ppt
 
Introduction to computer_system (for MBM first semester, BBA first semester, ...
Introduction to computer_system (for MBM first semester, BBA first semester, ...Introduction to computer_system (for MBM first semester, BBA first semester, ...
Introduction to computer_system (for MBM first semester, BBA first semester, ...
 
Basic of python for data analysis
Basic of python for data analysisBasic of python for data analysis
Basic of python for data analysis
 
Introduction to Embedded Systems
Introduction to Embedded SystemsIntroduction to Embedded Systems
Introduction to Embedded Systems
 
Basic of computers
Basic of computersBasic of computers
Basic of computers
 
Classification of computer_system
Classification of computer_systemClassification of computer_system
Classification of computer_system
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
Computer and its types
Computer and its typesComputer and its types
Computer and its types
 
134
134134
134
 
Chapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPUChapter 4 Microprocessor CPU
Chapter 4 Microprocessor CPU
 
Big Data Real Time Analytics - A Facebook Case Study
Big Data Real Time Analytics - A Facebook Case StudyBig Data Real Time Analytics - A Facebook Case Study
Big Data Real Time Analytics - A Facebook Case Study
 

More from MounikaPolabathina

Data Integration Solution for Fintech Airbyte.pdf
Data Integration Solution for Fintech  Airbyte.pdfData Integration Solution for Fintech  Airbyte.pdf
Data Integration Solution for Fintech Airbyte.pdfMounikaPolabathina
 
What is ETL and Zero ETL | Extract, Transform, Load
What is ETL and Zero ETL | Extract, Transform, LoadWhat is ETL and Zero ETL | Extract, Transform, Load
What is ETL and Zero ETL | Extract, Transform, LoadMounikaPolabathina
 
What is Amazon QuickSight | What is QuickSight
What is Amazon QuickSight | What is QuickSightWhat is Amazon QuickSight | What is QuickSight
What is Amazon QuickSight | What is QuickSightMounikaPolabathina
 
Amazon Redshift and QuickSight: Simplified guide
Amazon Redshift and QuickSight: Simplified guideAmazon Redshift and QuickSight: Simplified guide
Amazon Redshift and QuickSight: Simplified guideMounikaPolabathina
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Developing JIRA Plugins With Node.js.pdf
Developing JIRA Plugins With Node.js.pdfDeveloping JIRA Plugins With Node.js.pdf
Developing JIRA Plugins With Node.js.pdfMounikaPolabathina
 
Apache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdf
Apache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdfApache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdf
Apache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdfMounikaPolabathina
 
Optimizing static content in Django.pdf
Optimizing static content in Django.pdfOptimizing static content in Django.pdf
Optimizing static content in Django.pdfMounikaPolabathina
 
Selenium Implicit vs Explicit Waits.pdf
Selenium Implicit vs Explicit Waits.pdfSelenium Implicit vs Explicit Waits.pdf
Selenium Implicit vs Explicit Waits.pdfMounikaPolabathina
 
The Role of Data Engineering in Fintech.pdf
The Role of Data Engineering in Fintech.pdfThe Role of Data Engineering in Fintech.pdf
The Role of Data Engineering in Fintech.pdfMounikaPolabathina
 

More from MounikaPolabathina (13)

Data Integration Solution for Fintech Airbyte.pdf
Data Integration Solution for Fintech  Airbyte.pdfData Integration Solution for Fintech  Airbyte.pdf
Data Integration Solution for Fintech Airbyte.pdf
 
What is ETL and Zero ETL | Extract, Transform, Load
What is ETL and Zero ETL | Extract, Transform, LoadWhat is ETL and Zero ETL | Extract, Transform, Load
What is ETL and Zero ETL | Extract, Transform, Load
 
What is Amazon QuickSight | What is QuickSight
What is Amazon QuickSight | What is QuickSightWhat is Amazon QuickSight | What is QuickSight
What is Amazon QuickSight | What is QuickSight
 
Amazon Redshift and QuickSight: Simplified guide
Amazon Redshift and QuickSight: Simplified guideAmazon Redshift and QuickSight: Simplified guide
Amazon Redshift and QuickSight: Simplified guide
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Developing JIRA Plugins With Node.js.pdf
Developing JIRA Plugins With Node.js.pdfDeveloping JIRA Plugins With Node.js.pdf
Developing JIRA Plugins With Node.js.pdf
 
Apache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdf
Apache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdfApache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdf
Apache Spark vs. Hadoop Is Spark Set to Replace Hadoop.pdf
 
Optimizing static content in Django.pdf
Optimizing static content in Django.pdfOptimizing static content in Django.pdf
Optimizing static content in Django.pdf
 
Looping in Javascript.pdf
Looping in Javascript.pdfLooping in Javascript.pdf
Looping in Javascript.pdf
 
Selenium Implicit vs Explicit Waits.pdf
Selenium Implicit vs Explicit Waits.pdfSelenium Implicit vs Explicit Waits.pdf
Selenium Implicit vs Explicit Waits.pdf
 
Why Chose AWS.pdf
Why Chose AWS.pdfWhy Chose AWS.pdf
Why Chose AWS.pdf
 
6 reasons to use PhoneGap.pdf
6 reasons to use PhoneGap.pdf6 reasons to use PhoneGap.pdf
6 reasons to use PhoneGap.pdf
 
The Role of Data Engineering in Fintech.pdf
The Role of Data Engineering in Fintech.pdfThe Role of Data Engineering in Fintech.pdf
The Role of Data Engineering in Fintech.pdf
 

Recently uploaded

“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdfMuhammad Subhan
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfalexjohnson7307
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityVictorSzoltysek
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfdanishmna97
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Skynet Technologies
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهMohamed Sweelam
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewDianaGray10
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch TuesdayIvanti
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxFIDO Alliance
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxMasterG
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxFIDO Alliance
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data SciencePaolo Missier
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTopCSSGallery
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfSrushith Repakula
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Paige Cruz
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 

Recently uploaded (20)

“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 

Generators in Python.pdf

  • 1. APTUZ TECHNOLOGY SOLUTIONS GENERATORS IN PYTHON H T T P S : / / W W W . A P T U Z . C O M /
  • 2. INTRODUCTION TO GENERATORS Generators are special Python functions that use the "yield" keyword. They're not like regular functions; they have a superpower! What Are Generators? Generators allow pausing and resuming their execution. This unique feature opens the door to efficient memory management. Python's Hidden Magic Generators allow pausing and resuming their execution. This unique feature opens the door to efficient memory management. Python's Hidden Magic
  • 3. HOW GENERATORS WORK Generators can pause and resume their execution. The "Yield" Keyword: Execution of a generator function progresses until it encounters a "yield" keyword. At that point, the function's state is frozen, and local variables are stored in memory. When the generator is called again (e.g., in a for loop or using "next"), it continues from where it left off. This process can continue until the generator is exhausted. Resuming Execution:
  • 4. When dataset size exceeds memory capacity. Streaming data directly from a source to save memory. Perfect for big data and real- time analytics. Handling Large Datasets Efficient Data Processing Infinite Sequences WHERE GENERATORS SHINE Process data as it's generated, reducing memory footprint. Ideal for log parsing, sensor data analysis, and more. Lazy evaluation: Compute values only when needed. Create sequences without predefined endpoints. Infinite iterators for continuous data generation. Examples include number series, random data, and more.
  • 5. Traditionally, we would create a list of numbers up to 'n', which could occupy the entire system memory space. This approach is impractical when dealing with massive numbers, as it consumes excessive memory resources. Conventional Approach The Generator Solution: CODE EXAMPLE Imagine the task of printing the squares of numbers from 1 up to an extremely large number, say 200,000,000.
  • 6. 01 Generators excel at handling large datasets without consuming excessive memory. They load data as needed, making them ideal for big data processing. Memory Efficiency 02 Lazy evaluation allows generators to process data efficiently, especially when dealing with streams or sequences. No need to calculate everything upfront. Efficient Processing 03 Generators embody Python's philosophy of code readability and simplicity. They lead to cleaner, more elegant code that's easy to maintain. Pythonic Elegance BENEFITS OF GENERATORS
  • 7. https://www.aptuz.com/ info@aptuz.com 4th Floor, RAM SVR, Madhapur, HITEC City, Hyderabad - 500081 +(91)-9491754728 THANK YOU