SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
Python Generators
PySthlm Meetup #15 – Python
Best Practices – Oct 31, 2013
Samuel Lampa

twitter.com/smllmp
The “normal” (bad) way
The “normal” (bad) way

New temporary data structures
created and kept in memory
== BAD!!!
Using Generator function
Using Generator function

A yield (“return”) for
every iteration, so it can
be used immediately
without temp data structure
== GOOD!
Using Generator function

A yield (“return”) for
every iteration, so it can
be used immediately
without temp data structure
== GOOD!

So, this is the
generator function
Using Generator function

A yield (“return”) for
every iteration, so it can
be used immediately
without temp data structure
== GOOD!

So, this is the
generator function

… which can be
iterated over, like this ...
Python Generators - Talk at PySthlm meetup #15
Using list-comprehension syntax
Using list-comprehension syntax

Here, the generator function
Is defined in one row
Chaining generator functions
Chaining generator functions
Creds and more info:
●

David Beazleys Python Generator intro:

→dabeaz.com/generators
David Beazley on twitter: @dabeaz
Thank you!
Samuel Lampa
G+: gplus.to/saml
twitter: @smllmp
Blog: saml.rilspace.org
Developer @
www.uppmax.uu.se
www.farmbio.uu.se
www.rilpartner.se

More Related Content

PDF
Sparknize - Visualize CSV Data With Sparkline In Seconds
Kei Sawada
 
PDF
Dask - Parallelism for Machine Learning with Python
Matheus Pereira
 
PPTX
Continuous modeling - automating model building on high-performance e-Infrast...
Ola Spjuth
 
PDF
Hooking up Semantic MediaWiki with external tools via SPARQL
Samuel Lampa
 
PDF
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
Samuel Lampa
 
PPTX
Agile large-scale machine-learning pipelines in drug discovery
Ola Spjuth
 
PDF
SciPipe - A light-weight workflow library inspired by flow-based programming
Samuel Lampa
 
PDF
iRODS Rule Language Cheat Sheet
Samuel Lampa
 
Sparknize - Visualize CSV Data With Sparkline In Seconds
Kei Sawada
 
Dask - Parallelism for Machine Learning with Python
Matheus Pereira
 
Continuous modeling - automating model building on high-performance e-Infrast...
Ola Spjuth
 
Hooking up Semantic MediaWiki with external tools via SPARQL
Samuel Lampa
 
2nd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
Samuel Lampa
 
Agile large-scale machine-learning pipelines in drug discovery
Ola Spjuth
 
SciPipe - A light-weight workflow library inspired by flow-based programming
Samuel Lampa
 
iRODS Rule Language Cheat Sheet
Samuel Lampa
 

Similar to Python Generators - Talk at PySthlm meetup #15 (20)

PDF
Nancy CLI. Automated Database Experiments
Nikolay Samokhvalov
 
PPTX
Java Performance Tweaks
Jim Bethancourt
 
PPTX
Analyze database system using a 3 d method
Ajith Narayanan
 
PDF
Spark Meetup
Sahan Bulathwela
 
PDF
Operationalizing Clojure Confidently
Prasanna Gautam
 
ODP
Um2010
Jun Furuse
 
PDF
Automate Yo' Self
John Anderson
 
PPTX
Systematic Generation Data and Types in C++
Sumant Tambe
 
PPTX
Andromance - Android Performance
Orhun Mert Simsek
 
PDF
Django for IoT: From hackathon to production (DjangoCon US)
Anna Schneider
 
PDF
Testing and validating spark programs - Strata SJ 2016
Holden Karau
 
PDF
streamparse and pystorm: simple reliable parallel processing with storm
Daniel Blanchard
 
PPT
Euro python2011 High Performance Python
Ian Ozsvald
 
PDF
Beyond the Callback: Yield Control with Javascript Generators
Darren Cruse
 
PDF
Cheap HPC
Alex Moore
 
PDF
beyond-regular-regular-expressions-v20.pdf
ronaldopanuelos
 
PDF
Hacking iOS Simulator: writing your own plugins for Simulator
Ahmed Sulaiman
 
PDF
Python for scientific computing
Go Asgard
 
PDF
CoreData - there is an ORM you can like!
Tomáš Jukin
 
PDF
2012 07 making disqus realtime@euro python
Adam Hitchcock
 
Nancy CLI. Automated Database Experiments
Nikolay Samokhvalov
 
Java Performance Tweaks
Jim Bethancourt
 
Analyze database system using a 3 d method
Ajith Narayanan
 
Spark Meetup
Sahan Bulathwela
 
Operationalizing Clojure Confidently
Prasanna Gautam
 
Um2010
Jun Furuse
 
Automate Yo' Self
John Anderson
 
Systematic Generation Data and Types in C++
Sumant Tambe
 
Andromance - Android Performance
Orhun Mert Simsek
 
Django for IoT: From hackathon to production (DjangoCon US)
Anna Schneider
 
Testing and validating spark programs - Strata SJ 2016
Holden Karau
 
streamparse and pystorm: simple reliable parallel processing with storm
Daniel Blanchard
 
Euro python2011 High Performance Python
Ian Ozsvald
 
Beyond the Callback: Yield Control with Javascript Generators
Darren Cruse
 
Cheap HPC
Alex Moore
 
beyond-regular-regular-expressions-v20.pdf
ronaldopanuelos
 
Hacking iOS Simulator: writing your own plugins for Simulator
Ahmed Sulaiman
 
Python for scientific computing
Go Asgard
 
CoreData - there is an ORM you can like!
Tomáš Jukin
 
2012 07 making disqus realtime@euro python
Adam Hitchcock
 
Ad

More from Samuel Lampa (15)

PDF
SciCommander - Provenance reports for outputs of ad-hoc analyses
Samuel Lampa
 
PDF
Using Flow-based programming to write tools and workflows for Scientific Comp...
Samuel Lampa
 
PDF
Linked Data for improved organization of research data
Samuel Lampa
 
PDF
How to document computational research projects
Samuel Lampa
 
PDF
Reproducibility in Scientific Data Analysis - BioScience Seminar
Samuel Lampa
 
PDF
Batch import of large RDF datasets into Semantic MediaWiki
Samuel Lampa
 
PDF
Vagrant, Ansible and Docker - How they fit together for productive flexible d...
Samuel Lampa
 
PDF
AddisDev Meetup ii: Golang and Flow-based Programming
Samuel Lampa
 
ODP
First encounter with Elixir - Some random things
Samuel Lampa
 
PDF
Profiling go code a beginners tutorial
Samuel Lampa
 
PDF
Flow based programming an overview
Samuel Lampa
 
PDF
The RDFIO Extension - A Status update
Samuel Lampa
 
PDF
My lightning talk at Go Stockholm meetup Aug 6th 2013
Samuel Lampa
 
PDF
Thesis presentation Samuel Lampa
Samuel Lampa
 
PDF
3rd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
Samuel Lampa
 
SciCommander - Provenance reports for outputs of ad-hoc analyses
Samuel Lampa
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Samuel Lampa
 
Linked Data for improved organization of research data
Samuel Lampa
 
How to document computational research projects
Samuel Lampa
 
Reproducibility in Scientific Data Analysis - BioScience Seminar
Samuel Lampa
 
Batch import of large RDF datasets into Semantic MediaWiki
Samuel Lampa
 
Vagrant, Ansible and Docker - How they fit together for productive flexible d...
Samuel Lampa
 
AddisDev Meetup ii: Golang and Flow-based Programming
Samuel Lampa
 
First encounter with Elixir - Some random things
Samuel Lampa
 
Profiling go code a beginners tutorial
Samuel Lampa
 
Flow based programming an overview
Samuel Lampa
 
The RDFIO Extension - A Status update
Samuel Lampa
 
My lightning talk at Go Stockholm meetup Aug 6th 2013
Samuel Lampa
 
Thesis presentation Samuel Lampa
Samuel Lampa
 
3rd Proj. Update: Integrating SWI-Prolog for Semantic Reasoning in Bioclipse
Samuel Lampa
 
Ad

Recently uploaded (20)

PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Shreyas_Phanse_Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
SHREYAS PHANSE
 
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
AVTRON Technologies LLC
 
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Captain IT
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
This slide provides an overview Technology
mineshkharadi333
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 

Python Generators - Talk at PySthlm meetup #15