Last active
December 27, 2022 20:40
-
-
Save Rudxain/6969e78eae984313befdb6c393b952ea to your computer and use it in GitHub Desktop.
Slice list by searched values, instead of indices
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
from typing import Final, TypeVar | |
_T = TypeVar('_T') | |
# is there some way to avoid union type? | |
def slice_by_search(inp: (list | tuple)[_T], start: _T, end: _T): | |
'''LICENSE: Unlicense''' | |
i: Final = 1 + inp.index(start) | |
return inp[i: inp.index(end, i + 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment