1
# Copyright (C) 2004 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
__docformat__ = "restructuredtext"
19
__doc__ = "A miscellany of stuff"
22
class rewind_iterator:
23
"""A rewindable iterator wrapper"""
24
def __init__(self, base_iterator):
27
:param base_iterator: The iterator to make rewindable
28
:type base_iterator: Iterable of anything
30
self.base_iterator = base_iterator.__iter__()
32
self.list_iterator = self.read_items.__iter__()
38
return self.list_iterator.next()
42
item = self.base_iterator.next()
43
self.read_items.append(item)
47
"""Rewind and start iterating again from the sequence beginning."""
49
self.list_iterator = self.read_items.__iter__()
55
def invert_dict(dict):
57
for (key,value) in dict.iteritems():
62
# arch-tag: 9573f21a-15c4-4b9a-9f26-e744b3a58aa5