~divmod-dev/divmod.org/no-addperson-2190

« back to all changes in this revision

Viewing changes to Imaginary/pottery/iterutils.py

  • Committer: exarkun
  • Date: 2006-02-26 02:37:39 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:4991
Merge move-pottery-to-trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
"""Utilities for dealing with iterators and such.
 
3
"""
 
4
 
 
5
def interlace(x, i):
 
6
    """interlace(x, i) -> i0, x, i1, x, ..., x, iN
 
7
    """
 
8
    i = iter(i)
 
9
    try:
 
10
        yield i.next()
 
11
    except StopIteration:
 
12
        return
 
13
    for e in i:
 
14
        yield x
 
15
        yield e