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.2.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.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file strsplitter-1.0.2.tar.gz.

File metadata

  • Download URL: strsplitter-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 e6e9cf6ddc43d7446a96a29263cf0cf9758b51b695fd5d2fcf391aa28964f716
MD5 eecd9ced68a7d1dc807d43ac6b3ee8ee
BLAKE2b-256 c2c1aaa74c3033615a5cf12ba500fa5d9d3b644ecec7cc0783b83b1633d20877

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for strsplitter-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf87ac38b0c4918caf9b19fdd7cfca026f2d4acbe7e34551bf2a1ac1f4e34590
MD5 b72f73ce52a67d3c7e7d914c48a4cee6
BLAKE2b-256 fbd312498ee4e357372c4b32a1059b2f64f577fa891e76268c072070b69388fb

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