Getting Started
To get started with using the astrie package, follow these steps:
-
Installation
Install the package using pip:
pip install astrie
-
Importing
Import the
AsTrieclass from theastriemodule:from astrie import AsTrie
-
Object Initialization
Initialize an instance of the
AsTrieclass:trie = AsTrie()
Methods
Adding Words
To add words to the trie, you can use the following methods:
-
To add a single word:
trie.add("Python")
-
To add a list of words at once:
word_list = ["pineapple", "butterfly", "adventure", "rainbow", "whisper", "enchantment", "tranquility", "galaxy", "serendipity", "blossom", "chocolate", "meadow", "firefly", "symphony", "serenade", "moonlight", "horizon", "oasis", "velvet", "reflection", "sunrise", "wonder", "starlight", "cascade", "mystic", "melody", "twilight", "radiant", "journey", "destiny", "harmony", "peaceful", "embrace", "shimmer", "gentle", "serene", "dreamer", "captivate", "inspire", "tranquility", "cherish", "ethereal", "wanderlust", "cherished", "radiant", "adventure", "captivate", "radiant", "enjoy", "serenity","Python","Hello","World"] trie.add_many(word_list)
Removing Words
To remove words from the trie, you can use these methods:
-
To remove a single word:
trie.remove("Python")
-
To remove a list of words:
trie.remove_many(["Hello", "World"])
-
To empty the trie:
trie.clear()
Checking and Counting
You can perform various checks and obtain counts using these methods:
-
To check if a word exists in the trie:
exists = trie.has("horizon") print(exists) >>> True
-
To check if there are words that start with a given prefix:
starts_with = trie.starts_with("ad") print(starts_with) >>> True
-
To get the count of words that start with a prefix:
starts_with_count = trie.starts_with_count("ad") print(starts_with_count) >>> 2
-
To get the count of words equal to a given word:
count_equals = trie.count_equals("adventure") print(count_equals) >>> 2
-
To get the count of unique words in the trie:
unique_count = trie.unique_count() print(unique_count) >>> 48
Retrieving Words
You can retrieve words using these methods:
-
To get a generator object for all words in the trie:
all_words_generator = trie.all_words() for word in all_words_generator: print(word) >>> pineapple butterfly adventure ... World
-
To get a generator object for words that start with a prefix:
starts_with_generator = trie.words_starts_with("m") for word in starts_with_generator : print(word) >>> meadow melody moonlight mystic
Remember that for generator objects, you need to iterate over them to access the actual words they yield.
Note: This trie only works on alphabetical characters. If you want to use intergers typecast them into string before adding them to the trie.
Metadata
Release files for astrie 1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| astrie-1.2-py3-none-any.whl | Python 3 | none | any | Details |
Release files / astrie-1.2-py3-none-any.whl
| Download URL | astrie-1.2-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e432090c3487213dc28ac756d055a589ea26dc5792b4dbea1de0603e9aa6a6e4
|
|
BLAKE2b-256 checksum How to use checksums |
f2ab1d2895c9d81d1ae1dac1decbce347eb993e8cea5bfeb0aed3a6dc2291a5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for astrie 1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.