Returns the first element of the iterator or None when there are no elements. If the optional argument default is specified, that is returned instead of None when there are no elements.
(self, default=None)
| 671 | self.i, self.c = iterator, 0 |
| 672 | |
| 673 | def first(self, default=None): |
| 674 | """Returns the first element of the iterator or None when there are no |
| 675 | elements. |
| 676 | |
| 677 | If the optional argument default is specified, that is returned instead |
| 678 | of None when there are no elements. |
| 679 | """ |
| 680 | try: |
| 681 | return next(iter(self)) |
| 682 | except StopIteration: |
| 683 | return default |
| 684 | |
| 685 | def __iter__(self): |
| 686 | if hasattr(self, "_head"): |