On 2017-06-10 23:20, Neal Fultz wrote:
Hello python-ideas,
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.
We can currently do it like this in one line:
[(k, sum(1 for _ in g)) for k, g in groupby(sequence)]
However, it is slower than a "dedicated" solution.
Additionally, I don't know if what you are proposing is generic enough
for the standard library.
--
Bernardo Sulzbach
http://www.mafagafogigante.org/
mafagafogiga...@gmail.com
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/