Skip to content

Instantly share code, notes, and snippets.

@Peilonrayz
Last active February 22, 2018 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peilonrayz/e897757c722ef3682bdc51777a403dfe to your computer and use it in GitHub Desktop.
Save Peilonrayz/e897757c722ef3682bdc51777a403dfe to your computer and use it in GitHub Desktop.
Split
def split(iterable, sep):
indexes = itertools.chain([0], itertools.repeat(1))
for i, (key, group) in zip(indexes, itertools.groupby(iterable, sep.__ne__)):
if key:
carry = []
yield itertools.chain(group, carry)
carry.extend(group)
else:
for _ in itertools.islice(group, i, None):
yield iter([])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment