Practice mode Python

Which collections class is designed for fast appends and pops at both ends of a sequence?

Correct answer D. deque

Explanation

collections.deque, a double-ended queue, supports appends and pops from either end in approximately constant time. A list is fast at the right end, but inserting or popping at index 0 is O(n) because all other items must shift. deque is ideal for queues and sliding windows.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.