Skip to main content

It solves the problem of determining the combination in a sequence based on the some alphabet with a given length, and use combination to determine the iteration index.

Problem

There are several elements to iterate - a, b and c. How many possible combinations for unique enumeration if key size is 3? Or, which combination is at the tenth iteration? Or which iteration corresponds the aca combination?

For abc alphabet and 3 key size can be created the next iterations:

 0. aaa      1. aab      2. aac      3. aba      4. abb      5. abc
 6. aca      7. acb      8. acc      9. baa     10. bab     11. bac
12. bba     13. bbb     14. bbc     15. bca     16. bcb     17. bcc
18. caa     19. cab     20. cac     21. cba     22. cbb     23. cbc
24. cca     25. ccb     26. ccc

So, the maximum number of iterations - 27, for 10 iteration corresponds to baa combination and the aca combination - it is 7 iteration.

Theory

Use the arbitrary alphabet (set of available characters to create a key) and size of key can be created a sequence of unique combinations, where each new combination has its unique numeric index (from 0 to N - where the N is maximum number of possible combinations or infinity).

If specify the index (for example an ID in the table of database) - will be returned the combination (key) for this index, and if specify combination - will be returned it index.

P.s. The sequence is not created - just calculate the data of a specified element. This algorithm allows you to quickly get the result.

Example:

# INITIAL DATA
# =================
# Alphabet | abcde
# ---------+-------
# Key size | 3
#
# SEQUENCE
# ==============================================
# ID  |  0  |  1  |  2  | ... | 122 | 123 | 124
# ----+-----+-----+-----+-----+-----+-----+-----
# Key | aaa | aab | aac | ... | eec | eed | eee

lk = LordKey(alphabet='abcde', size=3)
lk.get_key_by_id(122) # eec
lk.get_id_by_key('ecc') # 122

The alphabet may be omitted then will be used value by default. If not set the size value - key size can be from one char to infinity.

Example:

# Size not specified.
lk = LordKey(alphabet='abc')
lk.get_key_by_id(1) # b
lk.get_key_by_id(10) # bab
lk.get_key_by_id(100) # bacab
lk.get_key_by_id(1000) # bbabaab
lk.get_key_by_id(10000) # bbbcabbab
lk.get_key_by_id(100000) # bcaacabbcab
lk.get_key_by_id(1000000) # bcbccbacacaab
lk.get_key_by_id(10000000) # caacbbaabbacbab

Metadata

Release files for LordKey 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for LordKey 0.0.3
File Size Uploaded
LordKey-0.0.3.tar.gz 4.3 kB Details

Release files / LordKey-0.0.3.tar.gz

Download URL LordKey-0.0.3.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9c1d97f26245d1718dcdbbc3b2795f87f1d530838a97af7985fec3aecf31067a
BLAKE2b-256 checksum
How to use checksums
e92bfde3d17306e7f819c76cd4765b9b959aa75be8c97ffb55fc90fd6e697a0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 release file

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page