https://github.com/julian-nash/python-run-length-encoder
a Python Run-Length encoder class with 3 methods
https://github.com/julian-nash/python-run-length-encoder
Last synced: 3 months ago
JSON representation
a Python Run-Length encoder class with 3 methods
- Host: GitHub
- URL: https://github.com/julian-nash/python-run-length-encoder
- Owner: Julian-Nash
- Created: 2019-04-02T15:33:11.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-02T15:36:44.000Z (about 6 years ago)
- Last Synced: 2025-01-24T14:18:07.548Z (4 months ago)
- Language: Python
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Python Run-Length Encoder
A RunLengthEncoder class with 3 available methods, all of which take an input string and return a compressed output string.
Examples:
- `encode_a`
```py3
from run_length_encoder import RunLengthEncoderencoder = RunLengthEncoder()
result = encoder.encode_a("abc123xyzaaabbbcccd")
print(result)
````encode_a` Returns a compressed string from an input string.
Note: This function will not return the character count in the return string if only a single instance of the character is found.
Result:
```sh
abc123xyz3a3b3cd
```- `encode_b`
```py3
from run_length_encoder import RunLengthEncoderencoder = RunLengthEncoder()
result = encoder.encode_b("abc123xyzaaabbbcccd")
print(result)
````encode_b` Returns a run-length encoded string from an input string, with a count for each character, followed by the character itself.
Result:
```sh
1a1b1c1112131x1y1z3a3b3c1d
```- `encode_c`
```py3
from run_length_encoder import RunLengthEncoderencoder = RunLengthEncoder()
result = encoder.encode_c("abc123xyzaaabbbcccd")
print(result)
````encode_c` uses a list comprehension to build the return string.
Result:
```sh
1a1b1c1112131x1y1z3a3b3c1d
```### Usage
Clone this repo & run:
```sh
python example.py
```### Tests
To run the small suite of unit tests:
```sh
python test.py
```