Back to Freecodecamp

Step 4

curriculum/challenges/english/blocks/workshop-breadth-first-search/68da6138d70960c197ec5eee.md

latest1.2 KB
Original Source

--description--

Now you'll set up the data structure to store your results. Create a variable named result and initialize it as an empty list. This list will store all the valid parentheses combinations you generate.

Update your return statement to return result instead of an empty list.

--hints--

You should declare a variable named result in your gen_parentheses function.

js
({ test: () => runPython(`
assert _Node(_code).find_function("gen_parentheses").has_variable("result")
`) })

You should initialize result as an empty list.

js
({ test: () => runPython(`
_result = _Node(_code).find_function("gen_parentheses").find_variable("result")
assert _result.is_equivalent("result = []") or _result.is_equivalent("result = list()")
`) })

You should return result at the end of your function.

js
({ test: () => runPython(`
assert _Node(_code).find_function("gen_parentheses").has_return("result")
`) })

--seed--

--seed-contents--

py
--fcc-editable-region--
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'
    
    return []
--fcc-editable-region--