Skip to content

Instantly share code, notes, and snippets.

@AN3223

AN3223/draft.rst Secret

Last active July 16, 2018 15:48
Show Gist options
  • Save AN3223/344d27279be6ee87e13c5fadf1af756d to your computer and use it in GitHub Desktop.
Save AN3223/344d27279be6ee87e13c5fadf1af756d to your computer and use it in GitHub Desktop.

Unnecessary list comprehension

When simply converting an iterable to a list, it's unnecessary to use list comprehension. The list() constructor can handle the iterable instead.

Anti-pattern

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

Best practice

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

References

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