A smart and flexible string joining library for Python developers.
Project description
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
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
File details
Details for the file smartjoiner-1.0.0.tar.gz.
File metadata
- Download URL: smartjoiner-1.0.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
146d7a1dae765161741cc509bb66c9079ead527204b751066ca415e89d495852
|
|
| MD5 |
110990302f90367edf5f03746819dc2a
|
|
| BLAKE2b-256 |
59c0e58bae7a12ef2c8f0f46377c2d94d0f540988210af19c61edd5c049527e0
|