A peekable class which caches the last item returned by next()
| 350 | ) |
| 351 | |
| 352 | class peekable2(peekable): |
| 353 | """ |
| 354 | A peekable class which caches the last item returned by next() |
| 355 | """ |
| 356 | |
| 357 | def __init__(self, iterable): |
| 358 | super().__init__(iterable) |
| 359 | self.current_item = None |
| 360 | |
| 361 | def __next__(self): |
| 362 | self.current_item = super().__next__() |
| 363 | return self.current_item |
| 364 | |
| 365 | tokens = peekable2(get_tokens(text)) |
| 366 |