Deque - is this valid python?


I need a buffer for appending/popping dictionaries as a buffer. I used a list, which was working fine but read that a list is not efficient. So I looked into deque.

mq = deque()
mq.append ({'1':'a','2':'b','3':'c'})

which is working, popleft() returns a dictionary.

But is this legal for deque, adding dicts?

Is there an option to add 2 dictionaries when initialising deque?

mq = deque({'1':'a','2':'b','3':'c'}, {'1':'a','2':'b','3':'c'})
mq = deque([{'1':'a','2':'b','3':'c'}, {'1':'a','2':'b','3':'c'}])

Do not work.

Best regards,


Yes, there should be no problem with having dictionaries in a deque. And for initialization, your second example should work just fine. No idea what didn’t work for you.

1 Like


mq = deque([{'1':'a','2':'b','3':'c'}, {'1':'a','2':'b','3':'c'}])

Indeed works. Must have been a typo.

Best regards

1 Like