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.3.tar.gz
(7.0 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.3.tar.gz.
File metadata
- Download URL: strsplitter-1.0.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8a6a714845e144be9c68ab7b57b7de4386b1c79cdc8f82da640ed0b03504373
|
|
| MD5 |
01da2d47429d5d0fe3d383cae4f50cb9
|
|
| BLAKE2b-256 |
5d9772502ffd924be53e8d98862c7ef223e08ffb2963df2335d84a77877a3fd8
|
File details
Details for the file strsplitter-1.0.3-py3-none-any.whl.
File metadata
- Download URL: strsplitter-1.0.3-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5773c967bc61c101ed2f36efd541199f27f81bda17ad67bba028ce2043f465b0
|
|
| MD5 |
614d3bc310d652dca69763b2e073f67f
|
|
| BLAKE2b-256 |
7ac3d2070165842d089cce040cdc36b792a753974b38ff487c10d1d20527c6c1
|