Skip to content

Converting values to lists using list comprehensions instead of list() #114

Description

@AN3223

Recently I've been using a lot of list comprehensions in Python. They're really useful. But I noticed that a lot of the time when I wanted to convert a generator or something into a list, I'd quickly write something like [x for x in whatever] and nothing else, when just list(whatever) would suffice. I suppose it's a readability thing?

So in short:

Anti-pattern

xs = (1, 2, 3, 4)
ys = [x for x in xs]

Best practice

xs = (1, 2, 3, 4)
ys = list(xs)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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