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
#1
I have a list of dictionaries, each dictionary contains keys relating to its health.

I am creating the list via the following as I don't want ever key in the dictionary.

computer_keys = ('id', 'hostname', 'lastSeenAt', 'threats', 'ProtectionEnabled', 'services', 'ipv4Addresses', 'associatedPerson', 'health')
for all_computers in computers_json["items"]:
    computer_dictionary = {key:value for key, value in all_computers.items() if key in computer_keys}
    computer_list.append(computer_dictionary)
The list looks like this

[
{
"associatedPerson": {
"viaLogin": "user"
},
"encryption": {
"volumes": [
{
"status": "notEncrypted",
"volumeId": "60BB3F30"
}
]
},
"health": {
"overall": "good",
"services": {
"serviceDetails": [
{
"name": "service",
"status": "running"
},

The issue I am having is, Health will return the dictionary below it. I just need the overall key, not all others. How can I do this?
Reply


Messages In This Thread
Retrieving dictionary keys within with another dictionay - by bazcurtis - Oct-28-2019, 12:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  KeyError while retrieving ESPN data john317ab 2 812 Nov-29-2023, 09:07 PM
Last Post: john317ab
  .get() not retrieving value? Sedos101 2 563 Aug-25-2023, 11:48 AM
Last Post: deanhystad
  [Solved] Retrieving a pdf from sqlite3 BigMan 4 2,319 Mar-12-2022, 01:56 PM
Last Post: deanhystad
  Retrieving a column from a data set using a function Bayle 6 2,338 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Retrieving Cookies whois1230 2 2,175 Nov-21-2020, 12:01 PM
Last Post: snippsat
  Adding keys and values to a dictionary giladal 3 2,484 Nov-19-2020, 04:58 PM
Last Post: deanhystad
  Problem: Retrieving Form data PythonDev 3 3,098 Oct-16-2020, 02:09 AM
Last Post: PythonDev
  access dictionary with keys from another and write values to list redminote4dd 6 3,246 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  Drop Keys From Dictionary donnertrud 8 3,698 May-30-2020, 11:39 AM
Last Post: DeaD_EyE
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,047 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