Skip to main content

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

stringdatadeque-1.1.3.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

StringDataDeque-1.1.3-py3-none-any.whl (45.5 kB view details)

Uploaded Python 3

File details

Details for the file stringdatadeque-1.1.3.tar.gz.

File metadata

  • Download URL: stringdatadeque-1.1.3.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for stringdatadeque-1.1.3.tar.gz
Algorithm Hash digest
SHA256 065f861182666018f2048250cc18bf04a62081485f0658ddac2300288df2fa18
MD5 1adec31a3584f15aa7c76a02553ea2ed
BLAKE2b-256 cabf6ddd15055c757dfd87de8c46bc6560d93470351440440fd1888d66724e67

See more details on using hashes here.

File details

Details for the file StringDataDeque-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for StringDataDeque-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cdd6b6a73706a27a4073174773590104deeb58162593f1d4e2906f623c678f4a
MD5 ee782ed17bcbd49f1b90861c65d3c427
BLAKE2b-256 6e49c0066b5ab2da135df4a01ce00653c7decabb7c65c311529b1913b1b66248

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page