def next(iterator, default=None):
    """A version of the built-in next function, for use with
       implementations of Python older then version 2.6.
    """
    try:
        return iterator.next()
    except StopIteration:
        if default:
            return default
        else:
            raise StopIteration