Skip to content

Instantly share code, notes, and snippets.

@Rudxain
Last active December 27, 2022 20:40
Show Gist options
  • Save Rudxain/6969e78eae984313befdb6c393b952ea to your computer and use it in GitHub Desktop.
Save Rudxain/6969e78eae984313befdb6c393b952ea to your computer and use it in GitHub Desktop.
Slice list by searched values, instead of indices
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