Skip to content

moreati/find-step

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

find-step

find-step supplements Python str.find() and bytes.find() methods with an extra step argument - just like slicing has s[start:end:step].

Usage

If step is None, 1, or omitted then behaviour is unchanged from str.find() or bytes.find().

>>> import find_step
>>> find_step.find('.a.a.a.a', 'a')  # Same as '.a.a.a.a'.find('a')
1

If step is 2 or higher then only indexes satisfying start + n * step are tried, where n >= 0.

>>> find_step.find('.a.a.a.a', 'a', None, None, 3)  # Tries index 0, then index 3
3
>>> find_step.find('hello', 'l', 1, None, 2)  # Tries index 1, then index 1 + 2 = 3
3
>>> find_step.find('abcde', 'c', 1, None, 2)  # Tries index 1, then 3, then 5
-1

If step is O then ValueError is raised, as in slice notation.

>>> find_step.find('abc', 'a', None, None, 0)
Traceback (most recent call last):
    ...
ValueError: slice step cannot be zero

Install

python3 -m pip install find-step`

or

uv pip install find-step

License

MIT

About

All of Python's str.find() goodness, now with a step argument

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages