Python Forum
Retrieving dictionary keys within with another dictionay
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving dictionary keys within with another dictionay
#5
Thanks Craig. That is working perfectly now.

Here is the new code

    for all_computers in computers_json["items"]:
        # Make a temporary Dictionary to be added to the sub estate list
        computer_dictionary = {key:value for key, value in all_computers.items() if key in computer_keys}
        if 'health' in computer_dictionary.keys():
            computer_dictionary['service_health'] = {'services': computer_dictionary['health']['services']['status']}
            computer_dictionary['threats'] = {'threats': computer_dictionary['health']['threats']['status']}
            computer_dictionary['health'] = {'overall': computer_dictionary['health']['overall']}
        computer_list.append(computer_dictionary)
The only issue left is, I really only want the bad or good, but I get the below. Is there anyway to tidy this up?

<class 'dict'>: {'id': '116bd3bf-00b9-42b1-bf11-ffc6de819084', 'hostname': 'DC', 'health': {'overall': 'good'}, 'ipv4Addresses': ['192.168.220.22'], 'ProtectionEnabled': True, 'lastSeenAt': '2018-11-14T17:07:28.240Z', 'service_health': {'services': 'good'}, 'threats': {'threats': 'good'}}
Reply


Messages In This Thread
RE: Retrieving dictionary keys within with another dictionay - by bazcurtis - Oct-29-2019, 11:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  KeyError while retrieving ESPN data john317ab 2 829 Nov-29-2023, 09:07 PM
Last Post: john317ab
  .get() not retrieving value? Sedos101 2 573 Aug-25-2023, 11:48 AM
Last Post: deanhystad
  [Solved] Retrieving a pdf from sqlite3 BigMan 4 2,345 Mar-12-2022, 01:56 PM
Last Post: deanhystad
  Retrieving a column from a data set using a function Bayle 6 2,362 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Retrieving Cookies whois1230 2 2,192 Nov-21-2020, 12:01 PM
Last Post: snippsat
  Adding keys and values to a dictionary giladal 3 2,512 Nov-19-2020, 04:58 PM
Last Post: deanhystad
  Problem: Retrieving Form data PythonDev 3 3,119 Oct-16-2020, 02:09 AM
Last Post: PythonDev
  access dictionary with keys from another and write values to list redminote4dd 6 3,271 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  Drop Keys From Dictionary donnertrud 8 3,752 May-30-2020, 11:39 AM
Last Post: DeaD_EyE
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,060 Dec-17-2019, 08:00 PM
Last Post: jasonashaw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020