Complete Search Implementation
Lesson 9 of 10 in Coddy's Social media Search Project - Python JSON Fundamentals course.
As a final challenge, you'll need to complete the search implementation, that takes the query filter string as input from the UI.
And returns a filtered list from the complete JSON list available in the backend.
Challenge
MediumWrite a function search that gets,
filter_query- string - Input string in the format -full_json- string - the complete JSON records. A sample of the entire list is given below:
And outputs mixed-array, which is …
Example:
Input -
type=user
{"result": [
{
"name": "Robert McNally",
"city": "Hawaii",
"type": "user",
"gender": "M"
}, {
"name": "Elizabeth Minelli",
"city": "Hawaii",
"type": "user",
"gender": "F"
}, {
"name": "Friendly Neighborhood Coder",
"city": "Trivandrum",
"type": "page" },
{
"name": "Coddy Official",
"city": "Haifa",
"type": "page"
}
]
}Expected Output - [{'name': 'Robert McNally', 'city': 'Hawaii', 'type': 'user', 'gender': 'M'}, {'name': 'Elizabeth Minelli', 'city': 'Hawaii', 'type': 'user', 'gender': 'F'}]
Explanation - The filter is on type=user. Your python function should filter out any JSON object from the result JSON array where type=user.
Try it yourself
def search(filter_query, full_json):
# Write code here