A string splitting utility with customizable splitters and filtering.
Project description
strsplit
A flexible string splitting utility for Python that allows splitting by different strategies and filtering the results using predicates. This package is inspired by the abseil StrSplit library.
[
]
Features
- Split by a delimiter string (
SplitByStr) - Split by fixed length chunks (
SplitByLength) - Split by any character in a set (
SplitByAnyChar) - Control maximum splits with
maxsplitparameter (default-1= no limit) - Filter out substrings via a predicate function in the main
splitfunction
Usage
from strsplit import split, SplitByStr, SplitByAnyChar, SplitByLength
# Split using a string delimiter
it = split(text="a,b,c", ",") # <=> it = split(text="a,b,c", splitter=SplitByStr(","))
print(list(it)) # --> ['a', 'b', 'c']
# Split by any chars
it = split(text="a,b;c-d", [",", ";", "-"]) # <=> it = split(text="a,b,c", splitter=SplitByAnChar(",;-"))
print(list(it)) # --> ['a', 'b', 'c', 'd']
# Split by length
it = split(text="abcdef", splitter=SplitByLength(2)) # <=> it = split(text="abcdef", 2)
print(list(it)) # --> ["ab", "cd", "ef"]
# Use a predicat to filter the result
it = split(",a,,b,c,", ",", lambda x : len(x) > 0)
print(list(it)) # --> ['a', 'b', 'c']
# Limit the number of substr
# Every splitter accepts another parameter maxsplit to limit the number of splits
it = split(text="a,b,c,d", SplitByStr(delimiter=",", maxsplit=2))
print(list(it)) # --> ['a', 'b']
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
strsplitter-1.0.1.tar.gz
(6.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strsplitter-1.0.1.tar.gz.
File metadata
- Download URL: strsplitter-1.0.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe101f4ade770d5298853c1d3350fed3f9124594cc1f5d1e0af4d880c6dee1ff
|
|
| MD5 |
fea38a29d1470a083b2e4b0211d1a416
|
|
| BLAKE2b-256 |
b3e61157fd3e6af029f86d653b52f096298cc2b655caeec14baeefca4c123439
|
File details
Details for the file strsplitter-1.0.1-py3-none-any.whl.
File metadata
- Download URL: strsplitter-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d77665db0823b0539f3261389aa89aa8ecb93ed16ec3a29168a82d18c84d18e
|
|
| MD5 |
9b0b9917b987becc04ae36378da58736
|
|
| BLAKE2b-256 |
1f1dcfd4a476b46e1592ab05c35c3d3cba9bd735caa682a5e93ff2276d415d5b
|