Back to Freecodecamp

Step 12

curriculum/challenges/english/blocks/learn-algorithm-design-by-building-a-shortest-path-algorithm/65b7d3319ebec69b983fb91b.md

latest1.1 KB
Original Source

--description--

As you can see from the output, .items() creates a data structure that stores each key-value pair in a distinct tuple. To iterate over the elements in those tuples you can add a second loop variable:

py
for i, j in dict.items():
    print(i, j)

Modify your for loop to take two loop variables and print both of them inside the loop body.

--hints--

You should modify your for loop to use two variables.

js
({ test: () => assert(runPython(`
import ast
var = _Node(_code).find_for_loops()[0].find_for_vars()
isinstance(var.tree, ast.Tuple)
`)) })

You should print both loop variables inside your for loop.

js
({ test: () => assert(runPython(`
var = _Node(_code).find_for_loops()[0].find_for_vars()
_Node(_code).find_for_loops()[0].find_bodies()[0].is_equivalent(f"print{var}")
`)) })

--seed--

--seed-contents--

py
--fcc-editable-region--
copper = {
    'species': 'guinea pig',
    'age': 2
}
copper['food'] = 'hay'
copper['species'] = 'Cavia porcellus'

for i in copper.items():
    print(i)
--fcc-editable-region--