Implement the Breadth-First Search Algorithm - Step 7

Tell us what’s happening:

I can’t tell what’s wrong with my code for this step. I added debugging steps that show the tuple was correctly unpacked. What am I missing?

Your code so far

def gen_parentheses(pairs):
    if not isinstance(pairs, int):
        return 'The number of pairs should be an integer'
    if pairs < 1:
        return 'The number of pairs should be at least 1'
    
    queue = [('', 0, 0)]
    result = []

# User Editable Region

    while queue:
        print(queue)
        tup = queue.pop(0)
        current, opens_used, closes_used = tup
    result.append(current)
    result.append(opens_used)
    result.append(closes_used)

# User Editable Region

    return result
print(gen_parentheses(2))

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15 Ddg/26.1

Challenge Information:

Implement the Breadth-First Search Algorithm - Step 7

Can you do this in one line instead?

        tup = queue.pop(0)
        current, opens_used, closes_used = tup

The tests don’t really like when you create new intermediary variables that aren’t specified by the instructions.

That is how I wrote the unpacking line. I deleted the debugging lines, but with or without them, when I execute, I get this error message: You should unpack the result into three variables: current, opens_used, and closes_used.

Right, but can you do this without the tup variable?

Why do this in two steps?

That did it. Thanks :ok_hand:

1 Like