Skip to main content

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.

PyPI version Supported Python versions Build License

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 maxsplit parameter (default -1 = no limit)
  • Filter out substrings via a predicate function in the main split function

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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strsplitter-1.0.3-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

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

Hashes for strsplitter-1.0.3.tar.gz
Algorithm Hash digest
SHA256 e8a6a714845e144be9c68ab7b57b7de4386b1c79cdc8f82da640ed0b03504373
MD5 01da2d47429d5d0fe3d383cae4f50cb9
BLAKE2b-256 5d9772502ffd924be53e8d98862c7ef223e08ffb2963df2335d84a77877a3fd8

See more details on using hashes here.

File details

Details for the file strsplitter-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for strsplitter-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5773c967bc61c101ed2f36efd541199f27f81bda17ad67bba028ce2043f465b0
MD5 614d3bc310d652dca69763b2e073f67f
BLAKE2b-256 7ac3d2070165842d089cce040cdc36b792a753974b38ff487c10d1d20527c6c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page