Skip to main content

Utility for joining string lists with flexible separator formatting.

Project description

Formatted Join ✅

Effortlessly join string sequences with flexible separator formatting for clear, polished output


License: MIT PyPI PyPI Status Downloads

Installation

PyPI

pip install formatted-join

uv

uv add formatted-join

Usage Examples

formatted_join(items: Sequence[str], separator=', ', final_separator=' and ', use_penultimate_separator=True) -> str

Joins items with flexible separator configuraton.

>>> from formatted_join import formatted_join
>>> formatted_join(['Hello', 'World'])
'Hello and World'
>>> formatted_join(('A', 'B', 'C'))
'A, B, and C'
>>> formatted_join(['X', 'Y', 'Z', 'W'], separator=' | ', final_separator=' & ')
'X | Y | Z & W'
>>> formatted_join(['Solo'])
'Solo'
>>> formatted_join(['', ''])
' and '
>>> formatted_join(
...     items=['Alpha', 'Bravo', 'Charlie', 'Delta'],
...     separator=' | ',
...     final_separator=' & ',
...     use_penultimate_separator=False
... )
'Alpha | Bravo | Charlie & Delta'
>>> formatted_join(['One', 'Two'], final_separator=' ~ ')
'One ~ Two'

formatted_join_conjunction(items: Sequence[str]) -> str

Convenience function that joins items using a comma and “and” before the last item.

>>> from formatted_join import formatted_join_conjunction
>>> formatted_join_conjunction(['Spring', 'Summer'])
'Spring and Summer'
>>> formatted_join_conjunction(['One', 'Two', 'Three'])
'One, Two, and Three'

formatted_join_disjunction(items: Sequence[str]) -> str

Convenience function that joins items using a comma and “or” before the last item.

>>> from formatted_join import formatted_join_disjunction
>>> formatted_join_disjunction(['Monday', 'Tuesday'])
'Monday or Tuesday'
>>> formatted_join_disjunction(['X', 'Y', 'Z'])
'X, Y, or Z'

formatted_join_unit(items: Sequence[str]) -> str

Joins items with commas only (no distinct final separator).

>>> from formatted_join import formatted_join_unit
>>> formatted_join_unit(['A'])
'A'
>>> formatted_join_unit(['A', 'B', 'C', 'D'])
'A, B, C, D'

formatted_join_narrow(items: Sequence[str]) -> str

Joins items with a single space separating each.

>>> from formatted_join import formatted_join_narrow
>>> formatted_join_narrow(['Only'])
'Only'
>>> formatted_join_narrow(['A', 'B', 'C'])
'A B C'
>>> formatted_join_narrow(['Line1', '-', 'Line2'])
'Line1 - Line2'

Development

  • Install Dependencies:
    • uv sync && uv pip install -r pyproject.toml --extra dev
  • Run formater:
    • uv run ruff check --select I --fix && uv run ruff format
  • Run type checking:
    • uv run mypy .
  • Run unit tests:
    • uv run formatted_join.py

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

formatted_join-1.0.1.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

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

formatted_join-1.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file formatted_join-1.0.1.tar.gz.

File metadata

  • Download URL: formatted_join-1.0.1.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.2

File hashes

Hashes for formatted_join-1.0.1.tar.gz
Algorithm Hash digest
SHA256 228e054b4f4d172cec5f1760eab39c3686943f6cc5541902690561c9a3280cd0
MD5 641241b4012d80a3b35a50d2e6e1a232
BLAKE2b-256 9e0c4f5cf394a542f895be6ba95a9d57ced50ffd99cc9588aed8633519f73bb9

See more details on using hashes here.

File details

Details for the file formatted_join-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for formatted_join-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 25edd04e83c170a1ac6ddbbc24ce91c68ae57214e954b7f4f03fb3333fc6abe1
MD5 29c6b3e75cf6e9d5e9551a3eb31a9299
BLAKE2b-256 b037ffc7404345238380c4cdc2beae178fab3a03230c6a8f16441f745fc27f24

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