Currently I fetch "list" data from my storage, "deque" it to work with that data.
After processing the fetched data I have to put them back into the storage. This won't be a problem as long as I am not forced (at least I think so) to use Python's standard "list" object to save this data.
Storage Service: Google Appengine.
My work-around would be:
dequeObj = deque(myData) my_list= list() for obj in dequeObj: my_list.append(obj)
but this seems not very optimal.
A deque is a set of linked memory blocks, where more than one element is stored in each memory block. A list is a set of elements dispersed in memory, i.e.: only one element is stored per memory "block".
For lists, it's always O(1). So, for accessing elements, lists are always a better choice, it's not at all what deques were designed for. Second, because deques are implemented as doubly-ended arrays, they have the advantage when appending or popping from both the right and the left side of a deque (measured as O(1)).
As you learned earlier, deque is implemented as a doubly linked list. So, every item in a given deque holds a reference (pointer) to the next and previous item in the sequence. Doubly linked lists make appending and popping items from either end light and efficient operations.
Reverse() Method Of Deque Class In Python reverse() reverses the sequence of elements present in a python deque object.
>>> list(collections.deque((1, 2, 3))) [1, 2, 3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With