Last active
June 17, 2022 14:01
-
-
Save adamchainz/f8135e5e1672e00605558a3a070010c5 to your computer and use it in GitHub Desktop.
Will McGugan's get_line_offsets challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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