[Python-ideas] Run length encoding

Nick Coghlan ncoghlan at gmail.com
Sun Jun 11 00:24:35 EDT 2017


On 11 June 2017 at 13:35, Neal Fultz <nfultz at gmail.com> wrote:
> Whoops, scratch that part about encode /decode.

Aye, decode is a relatively straightforward nested comprehension:

    def run_length_decode(iterable):
        return (item for item, item_count in iterable for __ in
range(item_count))

It's only encode that is currently missing a clear self-evidently
correct spelling, and I think that's more due to the lack of an
obvious spelling for "tell me how many items are in this iterable,
exhausting it if necessary" than it is to anything else.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list