200-901 · Question #224
Refer to the exhibit. Which command needs to be placed on the box where the code is missing to output the value of page_jd in the Python 3.7 script?
The correct answer is A. print(items.get('items')[0].get('page_id')). In the script, 'items' is a dictionary with a key 'items' whose value is a LIST (array) of objects. To access the first element of that list, you must use index [0] (or .get with index notation). Once you have the first list element (a dict), you then call .get('page_id') to…
Question
Refer to the exhibit. Which command needs to be placed on the box where the code is missing to output the value of page_jd in the Python 3.7 script?
Exhibit
Options
- Aprint(items.get('items')[0].get('page_id'))
- Bprint(items.get('items').get('page_id'))
- Cprint(items['items']['page_id'].keys())
- Dprint(items['items']['page_id'])
How the community answered
(36 responses)- A83% (30)
- B3% (1)
- C8% (3)
- D6% (2)
Explanation
In the script, 'items' is a dictionary with a key 'items' whose value is a LIST (array) of objects. To access the first element of that list, you must use index [0] (or .get with index notation). Once you have the first list element (a dict), you then call .get('page_id') to retrieve its value. Option B is wrong because it treats 'items' as a nested dict instead of a list. Options C and D use direct bracket notation on a list without indexing, which would raise a TypeError.
Topics
Community Discussion
No community discussion yet for this question.
