logo CodeStepByStep logo

collection_mystery8

Language/Type: Python collections list

Write the output produced by the following function when passed each of the following stacks:

def collection_mystery8(stack):
    queue = []
    myset = []
    while len(stack) != 0:
        n = stack.pop()
        if n % 2 == 0:
            queue.append(n)
        elif n not in myset:
            myset.add(n)
    for n in myset:
        stack.append(n)
    while len(queue) != 0:
        stack.append(queue.pop(0))
    print(stack)
[1, 2, 3, 4, 5]
[3, 2, 7, 3, 3, 4, 1, 1, 4]
[9, 7, 14, 7, 22, 7, 3, 14]
[8, 5, 1, 2, 1, 1, 2, 1, 4, 5]

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.