Skip to main content

SmartJoiner

SmartJoiner, created by Khalid Sulaiman Al-Mulaify, is a Python library that enhances the traditional join function by adding powerful and flexible features. Whether you're building dynamic outputs, enhancing readability, or working with complex lists, SmartJoiner provides the tools to handle it efficiently.


Features

✔ Conditional joining
✔ Customizable padding
✔ Indexed join
✔ Mixed separators
✔ Transform function
✔ Recursive joining
✔ Localized join
✔ Dynamic separator function


Installation

Install SmartJoiner via pip:

pip install smartjoiner

Usage

Import the SmartJoiner class and use its join method.

from smartjoiner import SmartJoiner

Feature Details & Examples

1. Conditional Joining

Join only elements that satisfy a given condition, such as filtering by string length.

result = SmartJoiner.join(
    ["orange", "banana", "cherry", "grapes", "melon"],
    separator=", ",
    condition=lambda s: len(s) == 6
)
print(result)
# Output: "orange, cherry"

2. Customizable Padding

Add padding to each element, such as enclosing each string in quotes or wrapping it with special characters.

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separator=", ",
    pad="'"
)
print(result)
# Output: "'apple', 'banana', 'cherry'"

3. Indexed Join

Include the index of each element in the joined string for tracking or formatting purposes.

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separator=" | ",
    with_index=True
)
print(result)
# Output: "0: apple | 1: banana | 2: cherry"

4. Mixed Separators

Use different separators between elements based on position or other criteria.

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separators=[" - ", " ~ "]
)
print(result)
# Output: "apple - banana ~ cherry"

5. Transform Function

Apply a transformation to each element before joining, such as uppercasing, reversing, or formatting strings dynamically.

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separator=", ",
    transform=str.upper
)
print(result)
# Output: "APPLE, BANANA, CHERRY"

6. Recursive Joining

Automatically flatten nested lists and join all elements into a single string.

result = SmartJoiner.join(
    ["apple", ["banana", "cherry"], "date"],
    separator=" - "
)
print(result)
# Output: "apple - banana - cherry - date"

7. Localized Join

Add a natural language conjunction like "and" or "or" before the last element for better readability.

Example 1: Using "and" (default)

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separator=", ",
    localized=True
)
print(result)
# Output: "apple, banana, and cherry"

Example 2: Using "or"

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separator=", ",
    localized=True,
    localized_word="or"
)
print(result)
# Output: "apple, banana, or cherry"

8. Dynamic Separator

Define a custom separator function to decide the separator based on the element's index or value.

result = SmartJoiner.join(
    ["apple", "banana", "cherry"],
    separator_function=lambda i, _: " - " if i % 2 == 0 else " ~ "
)
print(result)
# Output: "apple - banana ~ cherry"

License

This library is provided "as is", without warranty of any kind, express or implied.


Support

For questions, feedback, or support, feel free to reach out to Khalid Sulaiman Al-Mulaify via:

Email: khalidmfy@gmail.com
X (Twitter): @Python__Task

Metadata

Release files for smartjoiner 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smartjoiner 1.0.0
File Size Uploaded
smartjoiner-1.0.0.tar.gz 3.8 kB Details

Release files / smartjoiner-1.0.0.tar.gz

Download URL smartjoiner-1.0.0.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
146d7a1dae765161741cc509bb66c9079ead527204b751066ca415e89d495852
BLAKE2b-256 checksum
How to use checksums
59c0e58bae7a12ef2c8f0f46377c2d94d0f540988210af19c61edd5c049527e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page