How to use 'python filter list of dictionaries' in Python

Every line of 'python filter list of dictionaries' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
610def filter_object_entries_by_dict_values(result_object, response_dict_name):
611 """
612 Gets a dictionary (result_object) and filters it's keys by the values of another
613 dictionary (response_dict_name)
614 input: response_dict_name = 'file_indicators' - see API_PARAM_DICT above
615 result_object = {
616 "app": "web-browsing",
617 "vsys": 1,
618 "SHA256": "18c9acd34a3aea09121f027857e0004a3ea33a372b213a8361e8a978330f0dc8",
619 "UploadSource": "Firewall",
620 "src_port": 80,
621 "device_serial": "007051000050926",
622 "Seen": "2019-07-24T09:37:04",
623 "Name": "wildfire-test-pe-file.exe",
624 "user_id": "unknown",
625 "src_country": "United States",
626 "src_countrycode": "US",
627 "dst_port": 65168,
628 "device_countrycode": "US",
629 "Industry": "High Tech",
630 "Region": "us",
631 "device_country": "United States",
632 "ID": "179972200903"
633 }
634 output: {
635 "SHA256": "18c9acd34a3aea09121f027857e0004a3ea33a372b213a8361e8a978330f0dc8",
636 "Name": "wildfire-test-pe-file.exe"
637 }
638 :param result_object: a dictionary representing an object
639 :param response_dict_name: a dictionary which it's values are the relevant fields (filters)
640 :return: the result_object filtered by the relevant fields
641 """
642 af_params_dict = API_PARAM_DICT.get(response_dict_name)
643 result_object_filtered = {}
644 if af_params_dict and isinstance(result_object, dict) and isinstance(af_params_dict, dict):
645 for key in result_object.keys():
646 if key in af_params_dict.values(): # type: ignore
647 result_object_filtered[key] = result_object.get(key)
648 return result_object_filtered

Related snippets