Skip to content

Missing ignore_types arg when calling the method of flatten recursively #24

Open
@xiaofeig

Description

@xiaofeig

The code has missed ignore_types arg when calling the method of flatten recursively in the example about how to flatten a nested sequence.

src/4/how_to_flatten_a_nested_sequence/example.py

from collections import Iterable

def flatten(items, ignore_types=(str, bytes)):
    for x in items:
        if isinstance(x, Iterable) and not isinstance(x, ignore_types):
            yield from flatten(x)
        else:
            yield x

The corrected code is yield from flatten(x, ignore_types).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions