13 lines
430 B
Python
Executable file
13 lines
430 B
Python
Executable file
import json
|
|
|
|
def search_by_category(category, data):
|
|
# Initialize an empty list to hold matching items
|
|
matching_items = []
|
|
for entry in data:
|
|
# Check if the category matches
|
|
if category in entry.values():
|
|
matching_items.append(entry)
|
|
|
|
# Convert dictonary of results into a list:
|
|
list_of_matching_items = [list(d.keys())[0] for d in matching_items]
|
|
return list_of_matching_items
|