Use append to add an item to the end of the queue

In the following example, we create an empty list and then append six callers to it:

>>> callers = []

>>> for c in range(6):

... callers.append(c)

>>> callers

[0, 1, 2, 3, 4, 5]

2.

Use pop(0) in a while loop to retrieve an item from the front of the queue,

like this:

3.

>>> while callers:

4.

... callers.pop(0)

5.

6.

0

7.

1

8.

2

9.

3

10.

4

11.

5

Warning To avoid performance problems, don't use pop(0) with a large list (more than about 100 elements).

Warning To avoid performance problems, don't use pop(0) with a large list (more than about 100 elements).

Was this article helpful?

0 0

Post a comment