Introduction to Python Generators

Nov 30, 2015

Generators are an interesting feature of Python!

Generators are much similar to iterators except that they consume constant memory and are executed on demand making them a critical ingredient for optimization and in memory intense tasks.

Getting Started (Python 3.4.x)

Example 1: Declaring & Iterating

Example 2: Read small chunks from big buffer

Example 3: Find the first n number of the Fibonacci series

Example 4: Find different combinations

References

  1. Python generators and the yield keyword
  2. Generators for Engineers

Tags

  • python3
  • generator
  • yield
  • optimization
Harish Chakravarthy Harish Chakravarthy is an intrapreneur leveraging technology to make a positive difference. Interests include API integration, user experience, data visualization and analytics. Detailed bio.

Connect with Harish on Social Media Github Twitter LinkedIn