logo CodeStepByStep logo

collection_mystery9

Language/Type: Python collections list

Write the output produced by the following function when passed each of the following lists and integers.

def collection_mystery9(queue, p):
    stack = []
    count = 0
    size = len(queue)
    for i in range(size):
        element = queue.pop(0)
        if element < p:
            queue.append(element)
        else:
            count += 1
            stack.append(count)
            stack.append(element)

    while len(stack) != 0:
        queue.append(stack.pop())

    print(queue)
[1, 2, 3, 4, 5], p=4
[67, 29, 115, 84, 33, 71, 90], p=50

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.