0

i am trying to extract some information from a nested dictionary but having some trouble. I am going to share shortened version of the dictionary i am trying to extract information from here so it could be clear:

psets={'Windows_Alumil_Supreme_S77_PHOS_Fixed:Windows_Alumil_S77_Fixed_9_triple_glazing:1016843': {'id': 66476}, 'Analytical Properties': {'Analytic Construction': '', 'Define Thermal Properties by': 'User Defined', 'Heat Transfer Coefficient (U)': 1.63, 'Solar Heat Gain Coefficient': 0.27, 'Thermal Resistance (R)': 0.6134969325153374, 'Visual Light Transmittance': 0.74, 'id': 66617}, 'Construction': {'Construction Type': 'Window', 'Wall Closure': 'By host', 'id': 66618}, 'Dimensions': {'Height': 0.55, 'Rough Height': 2.115, 'Rough Width': 0.5650000000000001, 'Width': 2.1, 'Window Inset Depth': 0.01, 'id': 66619} {'Windows_Alumil_Supreme_S77_PHOS_Fixed:Windows_Alumil_S77_Fixed_8_triple_glazing:1016844': {'id': 68543}, 'Analytical Properties': {'Define Thermal Properties by': 'User Defined', 'Analytic Construction': '', 'Heat Transfer Coefficient (U)': 1.94, 'Solar Heat Gain Coefficient': 0.19, 'Thermal Resistance (R)': 0.5154639175257733, 'Visual Light Transmittance': 0.74, 'id': 68666}, 'Construction': {'Wall Closure': 'By host', 'Construction Type': 'Window', 'id': 68667}, 'Dimensions': {'Height': 0.55, 'Rough Height': 0.5650000000000001, 'Rough Width': 0.5650000000000001, 'Width': 0.55, 'Window Inset Depth': 0.01, 'id': 68668}

I want to extract each instance of the key 'Analytical properties' from the dictionary

For the above dictionary i used the code:

all_properties = []
for key, value in psets.items():
    if key == 'Analytical Properties':
        all_properties.append(value)
        
print (all_properties)

but i am only getting only one instance of 'Analytical Properties' whereas there are more than one. Can someone please help

  • Welcome to Stack Overflow. "but i am only getting only one instance of 'Analytical Properties' whereas there are more than one." That's the problem: **no, there aren't**. Just because you write them in the code doesn't mean the dictionary has them. A dictionary **cannot** have duplicate keys. – Karl Knechtel Feb 14 '23 at 17:46
  • If you *actually* have a data file that is supposed to be JSON, where this input is coming from, please be aware that it is not standard JSON. Dealing with that is a separate question, which is also a duplicate. – Karl Knechtel Feb 14 '23 at 18:11

0 Answers0