Source Code:
(back to article)
# list of dictionaries data = [{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}, {'id': 3, 'name': 'Charlie'}] # search value search_value = 'Bob' # search function def search_list_of_dicts(data, search_value): result = [] for item in data: if search_value in item.values(): result.append(item) return result # call the function and print the result result = search_list_of_dicts(data, search_value) print(result)
Result:
Report an issue