Convert iterator to an object that can be consumed multiple times. ``Regen`` takes any iterable, and if the object is an generator it will cache the evaluated list on first access, so that the generator can be "consumed" multiple times.
(it)
| 182 | |
| 183 | |
| 184 | def regen(it): |
| 185 | """Convert iterator to an object that can be consumed multiple times. |
| 186 | |
| 187 | ``Regen`` takes any iterable, and if the object is an |
| 188 | generator it will cache the evaluated list on first access, |
| 189 | so that the generator can be "consumed" multiple times. |
| 190 | """ |
| 191 | if isinstance(it, (list, tuple)): |
| 192 | return it |
| 193 | return _regen(it) |
| 194 | |
| 195 | |
| 196 | class _regen(UserList, list): |