Skip to content

Instantly share code, notes, and snippets.

@adamchainz
Last active June 17, 2022 14:01
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 adamchainz/f8135e5e1672e00605558a3a070010c5 to your computer and use it in GitHub Desktop.
Save adamchainz/f8135e5e1672e00605558a3a070010c5 to your computer and use it in GitHub Desktop.
Will McGugan's get_line_offsets challenge
def adam_get_line_offsets(text: str) -> list[int]:
offsets = [0]
n = 0
text_index = text.index
offsets_append = offsets.append
while True:
try:
n = text_index('\n', n) + 1
except ValueError:
break
offsets_append(n)
offsets.pop()
return offsets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment