Advertisement
HasteBin0

Python iter() neighbors() function

May 12th, 2023
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. def neighbors(x: Iterable[_T1], fill_item: _T1 = ...) -> Iterable[Tuple[_T1, _T1]]:
  2.     # def neighbors(x, fill_item = ...):
  3.     values = iter(x)
  4.     for first in values:
  5.         last = first
  6.         for v in values:
  7.             yield last, v
  8.             last = v
  9.         if last is first and fill_item is not Ellipsis:
  10.             yield fill_item, first
  11.             return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement