Skip to content

Instantly share code, notes, and snippets.

@scidam
Created November 8, 2021 12:15
Show Gist options
  • Select an option

  • Save scidam/146ec210b01677ad60056094fd12e53a to your computer and use it in GitHub Desktop.

Select an option

Save scidam/146ec210b01677ad60056094fd12e53a to your computer and use it in GitHub Desktop.
Offset and fill with '*' by default
def pairwise_offset(sequence, fillvalue='*', offset=0):
sequence = list(sequence)
a = sequence + [fillvalue] * offset if offset > 0 else [fillvalue] * offset + sequence
b = [fillvalue] * offset + sequence if offset > 0 else sequence + [fillvalue] * offset
return list(map(tuple, zip(a, b)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment