Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / html / python / lib / module-itertools.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-ConfigParser.html" />
<link rel="prev" href="module-sets.html" />
<link rel="parent" href="misc.html" />
<link rel="next" href="itertools-functions.html" />
<meta name='aesop' content='information' />
<title>5.16 itertools -- Functions creating iterators for efficient looping</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.15.4 Comparison to the"
href="comparison-to-builtin-set.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services"
href="misc.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5.16.1 Itertool functions"
href="itertools-functions.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="comparison-to-builtin-set.html">5.15.4 Comparison to the</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="itertools-functions.html">5.16.1 Itertool functions</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0071600000000000000000">
5.16 <tt class="module">itertools</tt> --
Functions creating iterators for efficient looping</A>
</H1>
<P>
<A NAME="module-itertools"></A>
<span class="versionnote">New in version 2.3.</span>
<P>
This module implements a number of iterator building blocks inspired
by constructs from the Haskell and SML programming languages. Each
has been recast in a form suitable for Python.
<P>
The module standardizes a core set of fast, memory efficient tools
that are useful by themselves or in combination. Standardization helps
avoid the readability and reliability problems which arise when many
different individuals create their own slightly varying implementations,
each with their own quirks and naming conventions.
<P>
The tools are designed to combine readily with one another. This makes
it easy to construct more specialized tools succinctly and efficiently
in pure Python.
<P>
For instance, SML provides a tabulation tool: <code>tabulate(f)</code>
which produces a sequence <code>f(0), f(1), ...</code>. This toolbox
provides <tt class="function">imap()</tt> and <tt class="function">count()</tt> which can be combined
to form <code>imap(f, count())</code> and produce an equivalent result.
<P>
Likewise, the functional tools are designed to work well with the
high-speed functions provided by the <tt class="module"><a href="module-operator.html">operator</a></tt> module.
<P>
The module author welcomes suggestions for other basic building blocks
to be added to future versions of the module.
<P>
Whether cast in pure python form or compiled code, tools that use iterators
are more memory efficient (and faster) than their list based counterparts.
Adopting the principles of just-in-time manufacturing, they create
data when and where needed instead of consuming memory with the
computer equivalent of ``inventory''.
<P>
The performance advantage of iterators becomes more acute as the number
of elements increases - at some point, lists grow large enough to
severely impact memory cache performance and start running slowly.
<P>
<div class="seealso">
<p class="heading">See Also:</p>
<div class="seetext"><p>The Standard ML Basis Library,
<em class="citetitle"><a
href="http://www.standardml.org/Basis/"
title="The Standard ML Basis Library"
>The Standard ML Basis Library</a></em>.</p></div>
<P>
<div class="seetext"><p>Haskell, A Purely Functional Language,
<em class="citetitle"><a
href="http://www.haskell.org/definition/"
title="Definition of Haskell and the Standard Libraries"
>Definition of Haskell and the Standard Libraries</a></em>.</p></div>
</div>
<P>
<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="itertools-functions.html">5.16.1 Itertool functions</a>
<LI><A href="itertools-example.html">5.16.2 Examples</a>
<LI><A href="itertools-recipes.html">5.16.3 Recipes</a>
</ul>
<!--End of Table of Child-Links-->
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="5.15.4 Comparison to the"
href="comparison-to-builtin-set.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="5. Miscellaneous Services"
href="misc.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="5.16.1 Itertool functions"
href="itertools-functions.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="comparison-to-builtin-set.html">5.15.4 Comparison to the</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="itertools-functions.html">5.16.1 Itertool functions</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>