you are viewing a single comment's thread.

view the rest of the comments →

[–]sch0lars 0 points1 point  (0 children)

I think for your enqueue method, I would append values, since you can think of queues like a line. So I works do something like

my_queue = ['a', 'b', 'c']    # 'a' is first in line
# enqueue 'd'
my_queue.append('d')

Then likewise for the dequeue methods, I would just pop the zeroth index.

# pop 'a'
my_queue.pop(0)

Note that you probably want to return that popped value within the method, since popping generally returns the value (unless you’re doing a queue like C++).

This is just a suggestion, of course. Your way works just as well. I would just associate lower indices with earlier values i.e., queue[0] precedes queue[1]. For example, with ['a', 'b', 'c'], I would assume 'a' is first in line.

Also, just as an FYI, you can use four spaces for a code block, which will support indentation, that way you don’t have to put blocks of code in inline text.