HasteBin0

Python `str.split()` Generator

Jul 13th, 2020
1,605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # https://stackoverflow.com/a/9773142
  2. def split_iter(string: str, divider: str) -> Generator[str, None, None]:
  3.     div_size = len(divider)
  4.     start = 0
  5.     while True:
  6.         idx = string.find(divider, start)
  7.         if idx == -1:
  8.             yield string[start:]
  9.             break
  10.         yield string[start:idx]
  11.         start = idx + div_size
Advertisement
Add Comment
Please, Sign In to add comment