Get the context around an index location in a string
Project description
stringcontext
Simple Python library functions for getting the context around an index location in a string.
This library was designed to handle retrieving a given amount of context around, before, or after an index location in a string.
context_after
: returns the string ofn
characters after the given index, or until the end of the string.context_before
: returns the string ofn
characters before the given index, or until the beginning of the string.context
: returns the full string of the context before, after, and including the character at index.
The code handles out of range issues on both ends of the string.
Based on the grep program's -C
option switch
Usage
import stringcontext
string = "Hello World test"
index = 5 # the space char
c = stringcontext.context(string, index, 5)
# "Hello World"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stringcontext-1.0.0.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for stringcontext-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 045d1fe435a01c050c4d8563f8cd60625bc4a4f1dfc357dec6001c7c840b71e4 |
|
MD5 | ff559302cc18fa0a9aa41bb701bfd55a |
|
BLAKE2b-256 | e91bbdfb65f31014117f6a1140116e0e19ca3ce9413e8256c9ece3f5d3230f0e |