Skip to content

Minor improvement to run_length() #858

@rhettinger

Description

@rhettinger

The existing code unnecessarily unpacks the args and then repacks them. Also, it uses a pure Python generator-expression when we already have a C speed itertool:

    @staticmethod
    def decode(iterable):
        return chain.from_iterable(repeat(k, n) for k, n in iterable)

New code:

    @staticmethod
    def decode(iterable):
        return chain.from_iterable(starmap(repeat, compressed))

The edit shifts to a more functional style and eliminates the uninformative variable names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions