Code Monkey home page Code Monkey logo

py-leximited's Introduction

PY-LEXIMITED

by LCF NERD 218

LEX-ENCODING IN PYTHON

Lexicographically Delimited Encoding for python, why not ay...

See: https://github.com/elenasa/ULAM/wiki/Appendix-D:-Leximited-Format

Following on from: https://github.com/walpolea/leximitedjs

WHY? : https://twitter.com/walpolea/status/1260954256292458497

LIKE THIS? CHECK OUT => https://www.livingcomputation.org/


INSTALL

https://pypi.org/project/leximited/1.1.1/

pip install leximited


IMPORT

import leximited


USE

Call leximited.to_leximited() with numbers (int or str) or arbitrary strings to get their leximited version.

Call leximited.from_leximited() with lex-encoded numbers (int or str) or arbitrary lex-encoded strings to get their "normal" version.

Also supports lists and tuples and allows for mixed lists with lex-encoding on numbers only, see examples below.

print(f'INTEGERS: {leximited.to_leximited(1)}')
INTEGERS: 11
print(f"NUMBERS WITH LEADING 0s: {leximited.to_leximited('002')}")
NUMBERS WITH LEADING 0s: '12'
print(f'BIG NUMBERS: {leximited.to_leximited(2000000000)}')
BIG NUMBERS: 92102000000000
print(f"SHORT STRINGS: {leximited.to_leximited('Bh3!!!')}")
SHORT STRINGS: 6Bh3!!!
print(f'LONG STRINGS: {leximited.to_leximited("a man, a plan, a guy: eleets")}')
LONG STRINGS: 9228a man, a plan, a guy: eleets
print(f"EMPTY STRINGS: {leximited.to_leximited('')}")
EMPTY STRINGS: 0

Also takes lists or tuples, and optionally preserve non-number strings as their original form (convert_text defaults to True to lex-encode everything).

in_list = [1, '002', 2000000000, 'Bh3!!!', 'a man, a plan, a guy: eleets', '']
print(f'INPUT: {in_list}')
leximited_list = leximited.list_to_leximited(in_list, convert_text=True)
print(f'LEXIMITED: {leximited_list}')
back_again = leximited.list_from_leximited(leximited_list)
print(f'AND BACK AGAIN: {back_again}')

INPUT: [1, '002', 2000000000, 'Bh3!!!', 'a man, a plan, a guy: eleets', '']
LEXIMITED: [11, '12', 92102000000000, '6Bh3!!!', '9228a man, a plan, a guy: eleets', '0']
AND BACK AGAIN: [1, '2', 2000000000, 'Bh3!!!', 'a man, a plan, a guy: eleets', '']

Note that the leading zeros are lost when converting back again.

py-leximited's People

Contributors

isaac-art avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

hermetique

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.