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
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
StringDataDeque-1.0.1.tar.gz
(62.5 kB
view details)
Built Distribution
File details
Details for the file StringDataDeque-1.0.1.tar.gz
.
File metadata
- Download URL: StringDataDeque-1.0.1.tar.gz
- Upload date:
- Size: 62.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4b57f3f3bec5f5f38022f494c440f914f8d7026f681d29d4e224f3664dca094 |
|
MD5 | 3eedf68e00cd1ad05245456310aabe03 |
|
BLAKE2b-256 | bd3e64b6f879d75a41c0e9938de7c6560ca0687f4bd5fd1625628ba844417035 |
File details
Details for the file StringDataDeque-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: StringDataDeque-1.0.1-py3-none-any.whl
- Upload date:
- Size: 45.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba855c9198ed244c07c1f7bc6470e5dc4b5cbf50b38ea01121684a8ef1ce5008 |
|
MD5 | 05cc61eeca4ef11305868ef9701a6f30 |
|
BLAKE2b-256 | 6f74f34270613a4f998b1c790b2166437ff37a2c81b46e0220b8eeed0c3b8fac |