nerdexam
Cisco

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…

Understanding and Using APIs

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

200-901 question #224 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)
  • A
    83% (30)
  • B
    3% (1)
  • C
    8% (3)
  • D
    6% (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

#Python data structures#Dictionary access#List indexing#JSON data parsing

Community Discussion

No community discussion yet for this question.

Full 200-901 Practice