exam questions

Exam 200-901 All Questions

View all questions & answers for the 200-901 exam

Exam 200-901 topic 1 question 50 discussion

Actual exam question from Cisco's 200-901
Question #: 50
Topic #: 1
[All 200-901 Questions]

Refer to the exhibit.

A REST API returns this JSON output for a GET HTTP request, which has been assigned to a variable called `vegetables`. Using Python, which output is the result of this command? print(filter(lambda 1: 1['type'] == 'fruit', vegetables) [0]['items'][0]['items'][0])

  • A. {'color': 'green', 'items': ['kiwi', 'grape']}
  • B. ['kiwi', 'grape']
  • C. lettuce
  • D. kiwi
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
evilgoat
Highly Voted 1 year, 2 months ago
Selected Answer: D
it is kiwi but that function is very syntactically wrong 1) lambda functions can't be called integers, so it should be something like "lambda <name>: <name>["type'"] == ..." 2) filter() returns an iterator and is not directly subscriptable, meaning that you need to actually iterate over it: for item in filter(lambda name: name["type"] == "fruit", data): print(item) this returns: {'type': 'fruit', 'items': [{'color': 'green', 'items': ['kiwi', 'grape']}, {'color': 'red', 'items': ['strawberry', 'apple']}]} 3) [0]['items'][0]['items'][0] is also syntactically incorrect since the outer-most object is a dictionary not a list, however: for item in filter(lambda name: name["type"] == "fruit", data): print(item['items'][0]['items'][0]) does actually return "kiwi" another quality question from cisco
upvoted 6 times
evilgoat
1 year, 2 months ago
oh, i just noticed that i named my variable "data" instead of "vegetables"
upvoted 1 times
...
...
Remus27
Most Recent 6 months, 3 weeks ago
The [0]['items'][0]['items'][0] exactly points to the -> "kiwi" 1. 0th element of response = first dictionary 2. then the "items" key 3. 0th list element of "items" is the nested dictionary 4. items is again a key inside it and at 0th indec inside the list is "kiwi"
upvoted 1 times
...
Addas1
1 year, 3 months ago
Can someone explain how it is Kiwi? I don't understand what "[0]['item']" means?
upvoted 1 times
...
macxsz
1 year, 11 months ago
Selected Answer: D
This here: [0]['items'][0]['items'][0] Points to "kiwi", which seems to be the correcto answer
upvoted 3 times
...
anonymous1966
2 years, 1 month ago
With no special chars: A REST API returns this JSON output for a GET HTTP request, which has been assigned to a variable called “vegetables”. Using Python, which output is the result of this command? print(filter(lambda 1: 1[ ‘type’ ] == ‘fruit’, vegetables) [0][‘items’][0][‘items’][0]) A . {‘color’: ‘green’, ‘items’: [‘kiwi’, ‘grape’]} B . [‘kiwi’, ‘grape’] C . lettuce D . kiwi
upvoted 2 times
...
Appearngthissunday
2 years, 2 months ago
Kiwi is the right answer
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago