Back to Freecodecamp

Step 6

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

latest1.1 KB
Original Source

--description--

To add a new key-value pair after declaring a dictionary, you can indicate the key in the same way you would access an existing key, and set the value of the new key by using the assignment operator:

py
my_dict = {
    'name': 'Michael',
    'occupation': 'Lumberjack'
}

my_dict['country'] = 'Canada'

Delete your print() call. Then, after the copper declaration, add the key 'food' to your dictionary and set its value to 'hay'.

--hints--

You should not have print(copper['age']) in your code.

js
({ test: () => assert.notMatch(code, /^print\(\s*copper\s*\[\s*("|')age\1\s*\]\s*\)/m) })

You should add the key 'food' to copper after declaring the dictionary.

js
({ test: () => assert.match(code, /copper\s*\[\s*("|')food\1\s*\]/) })

You should set copper['food'] to 'hay' after declaring the dictionary.

js
({ test: () => assert.match(code, /^copper\s*\[\s*("|')food\1\s*\]\s*=\s*("|')hay\2/m) })

--seed--

--seed-contents--

py
--fcc-editable-region--
copper = {
    'species': 'guinea pig',
    'age': 2
}
print(copper['age'])
--fcc-editable-region--