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)
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 justlist(whatever)would suffice. I suppose it's a readability thing?So in short:
Anti-pattern
Best practice