Python

  1. Home
  2. Computing & Technology
  3. Python

Transitioning from 2.x to 3.0

From Al Lukaszewski, for About.com

4 of 6

From Lists and Tuples to Iterators

Additionally, other Python functions that used to return lists now return iterators. This helps to save on system resources in that the iterator is not a static list of items (and so consuming RAM, etc.) but rather generates the next item in a series starting from the value of the last item issued. If the iterator has not been used before, it naturally starts with the first item.

In Python 3.0, map() and filter() return iterators, not lists. A list object can be created quickly, however, by passing the call through list(): list(map(x)).

Also, range() now returns an iterator like xrange() did in 2.5 and before. xrange() no longer exists in 3.0.

Finally, zip() no longer returns a list of tuples but an iterator that returns tuples.

Explore Python

About.com Special Features

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Python

  1. Home
  2. Computing & Technology
  3. Python
  4. Python 3.0
  5. Learn Python 3.0 - Python 3.0 Tutorials - Python 3.0 Transition Guide - From Lists and Tuples to Iterators

©2009 About.com, a part of The New York Times Company.

All rights reserved.