Basic introduction to generators / iterators

All new tutorial are submitted here.
They will be moved to the main Tutorials section once they have been approved by mods and admins.

Basic introduction to generators / iterators

Postby Kebap » Tue Feb 10, 2015 1:13 pm

Great read:

stranac wrote:Generators are a very useful tool and an important language concept, knowing more about them can't hurt.
I'd recommend this as an introduction: http://nedbatchelder.com/text/iter.html


The text starts out with improving some common complications from other languages like the following, before going on to more advanced examples of uses of generators, iterators, etc. Simple descriptions and thoughtful suggestions.

Code: Select all
for i in range(len(x)):
  return x(i) # complicated, locates elements by index

for e in x:
  return e # easy access to every element
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap
 
Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Basic introduction to generators / iterators

Postby micseydel » Tue Feb 10, 2015 5:50 pm

Yeah, I love that site! I did a presentation in college to the computer science club about iteration in Python where that site was like 90% of the inspiration.
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to Tutorial Submissions

Who is online

Users browsing this forum: Bing [Bot] and 2 guests