Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a deque object into list

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.

like image 562
Julius F Avatar asked Apr 24 '11 21:04

Julius F


People also ask

Is a deque a list?

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".

Is deque better than list?

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)).

Is a deque a list Python?

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.

How do you reverse a deque in Python?

Reverse() Method Of Deque Class In Python reverse() reverses the sequence of elements present in a python deque object.


1 Answers

>>> list(collections.deque((1, 2, 3))) [1, 2, 3] 
like image 145
Ignacio Vazquez-Abrams Avatar answered Sep 21 '22 16:09

Ignacio Vazquez-Abrams