[Python-ideas] Run length encoding
Serhiy Storchaka
storchaka at gmail.com
Sun Jun 11 00:57:24 EDT 2017
More information about the Python-ideas mailing list
Sun Jun 11 00:57:24 EDT 2017
- Previous message (by thread): [Python-ideas] Run length encoding
- Next message (by thread): [Python-ideas] ImportError raised for a circular import
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
11.06.17 05:20, Neal Fultz пише: > I am very new to this, but on a different forum and after a couple > conversations, I really wished Python came with run-length encoding > built-in; after all, it ships with zip, which is much more complicated :) > > The general idea is to be able to go back and forth between two > representations of a sequence: > > |[1,1,1,1,2,3,4,4,3,3,3]| > > and > > |[(1, 4), (2, 1), (3, 1), (4, 2), (3, 3)]| > > where the first element is the data element, and the second is how many > times it is repeated. > > I wrote an encoder/decoder in about 20 lines ( > https://github.com/nfultz/rle.py/blob/master/rle.py ) and would like to > offer it for the next version; I think it might fit in nicely in the > itertools module, for example. I am curious about your thoughts. RLE is just a general idea. Concrete implementations in file formats and protocols have different limitations and peculiarities. Different schemes are used for encoding lengths and values, short repetition sequences usually are not encoded with RLE, as well as repetition sequences of specific values, there are limitations on the maximal length. The implementation of the general idea is simple, but is not helpful in concrete cases.
- Previous message (by thread): [Python-ideas] Run length encoding
- Next message (by thread): [Python-ideas] ImportError raised for a circular import
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list