Skip to content

Replace for-append with generator #55

@Tadaboody

Description

@Tadaboody

New smell

Smelly code

li = list()
for x in other_iterable:
    # Body
    li += expr

Fixed code

def generate_li():
    # Body
    yield expr
li = list(generate_li())

Why is it smelly?

Not as smelly:tm: as other things, but in some cases it makes more sense, and more people should be aware of the possibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    newThis issue hasn't been looked at yetsmellA new smell to report and fix

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions