Which is faster and more pythonic?
- reverse an appended list
- start prepending the list from the start
- using
deque
E.g. here's ome made-up data to store into a new list
# Let's say my function outputs these output individually.
x = [12,34,44,346,345,876,123]
Reversing an appended list:
new_list = []
for i in x:
new_list.append(i)
new_list = newlist[::-1]
Prepending to the list:
new_list = []
for i in x:
new_list.insert(0,i)
Using deque:
from collections import deque
for i in x:
x.appendleft(i)
Please note that my question is not how to reverse list. Please also assume that the list is of size ~20,000.