Useful when building a string from data that can be converted into a string, in parts.
Project description
StringDataDeque
Useful when building a string from data that can be converted into a string, in parts.
Installation
https://pypi.org/project/StringDataDeque/
pip install StringDataDeque
Uses
This is designed to be a drop-in replacement for when you might want to append to a string in a loop.
Benefits
- Around 5 times faster than the naive implementation of appending to a string, such as
x = "" for x in collection: x+="new string"
- Provides many extra features that help simply code.
Examples
sd = StringDeque(sep="\n")
for x in collection:
sd += x
# StringDeque is a specialization of StringDataDeque where conversion func is "str"
# this allows any datatype to be used which can convert to str
sd += 1
print(sd)
You can also pipe data into the StringDeque
sd = StringDeque()
sd = [1,2,3,4,5] | sd
# or
sd |= [1,2,3,4,5]
StringDataDeque implements the "contains" method so you can search within it
sd = StringDeque(["line_one","line_two"],sep="\n")
if "line_one" in sd:
print("yes")
If you need more control over how data is added to the deque either use StringDataDeque or one of its subclasses.
# convert_func is called when data is added, and format_func is called when data is printed.
int_sdd =StringDataDeque(data="test", convert_func=int, format_func=str,sep=" ")
int_sdd |= ["1","2","3","4","5"]
assert int_sdd[0] == 1
assert str(int_sdd) == "1 2 3 4 5"
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stringdatadeque-1.2.1.tar.gz.
File metadata
- Download URL: stringdatadeque-1.2.1.tar.gz
- Upload date:
- Size: 51.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98ced0efa2f956d543f0650799d7979d0df1229bb5d0e17710136c001454107f
|
|
| MD5 |
e630ba47f393d21932317a8c93be9839
|
|
| BLAKE2b-256 |
85ddeb41aa7ec9ecbcd6e0ae3cf7d4d7e6f65e3f5bdd6b07ec9c24563f9446bc
|
File details
Details for the file StringDataDeque-1.2.1-py3-none-any.whl.
File metadata
- Download URL: StringDataDeque-1.2.1-py3-none-any.whl
- Upload date:
- Size: 35.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc1adf86f6ba1041c2be4da2682f9545d83d8ff24ebcfc2397b3b05afd823cdc
|
|
| MD5 |
998d720687a760f965bd7bb6f50b2d44
|
|
| BLAKE2b-256 |
556a88247f8226a7d7709bc3fac57efa97b0bbc385a7dae8993d33e1daf27402
|