title: How to extract all data keys and values in a nested python dict
body: <p>I have a JSON response from an API call in python, this is of dict type and I need to extract all the keys and values by traversing through the nested dictionary.
  I need some help to achieve this, what could be the best approach to check whether an item in the primary dict is another dict or just a key with a single value and not another dict.</p>
  
  <pre><code>{'html_attributions': [],
   'next_page_token': 'CrQEJAIAAO1gjIXdvnDjB40bRlRk9xUvHVqB_ZeYxmscrvINB13WdRTHfCoNorfeyJIc8yiW07HzrnxlU90hFiX0hn2Pe30iIeL5d8FBwBUjhC483L0jCdx7s0b4TY85rQnghHoa0lPKDSMRMDBedJZCaMbn-lWqpDdvZtakJLuZpIYjw8Q0R6aGsmcej5oWS0xZ6ovsoRz-coicPea_1lDeDVNFkae3SDGtJ3p2WgXu6vzhfUowCi4K9vUOP2WT_e0Q_UUrP0X1ASQMN4kMh3ibcbOXMGHoi4MkpYe1B2tmfdN5vSkH929o6FbXwd7aciZWswFnq1rmARV4FSaL8fbtyX0juDddOP4g4NcVi6MnCXRVw23S61d-Pu3X85gc-dIXqigcCPnhOKVmqG3FdZC_fDTqgB3nXBmHOETHLjdHLa0BfMT-mqamZ2Zr--sBa05JEgbb8YquLsgS4rb-dLJj4U0Gq0jI7BNstRt0Dszy8bj9admRe9xYFGUlIs7ex9yCAilhJ4j4U91FEi4Po89sHguxkpuRGEQv88whgnfvTLCg0YbA71DPv7OhfR4PwbdWk1n6ElUCOLHR5lWarWU4iAhPjNBKqnXethE32qVakubNU69EEgHu0Ojq87XkaGuWBV6qaiZKmJFkY1dUKNPv0udEmesu9MQP35jpXRRr7r_EaN5neWL57pmyXFAuzQuRxa-7CORw_Sa2FTiBRIxTcpz3gAAP5X3CCKctxkSb8DruZ2YGEhBMAnIESGWZXQDTnGKd-Xf2GhQjt_LI8xL1-V8hHdTL-lK2DHJWNw',
   'results': [{'formatted_address': 'University of Lagos, Akoka Rd, Yaba, Lagos, Nigeria',
     'geometry': {'location': {'lat': 6.5151087, 'lng': 3.3886033},
      'viewport': {'northeast': {'lat': 6.522969049999999,
        'lng': 3.394707349999999},
       'southwest': {'lat': 6.50730845, 'lng': 3.38207915}}},
     'icon': 'https://maps.gstatic.com/mapfiles/place_api/icons/school-71.png',
     'id': '6bd1760a7bca49e16e560fec68f6125c2440f5ca',
     'name': 'UNILAG Nigeria',
     'opening_hours': {'open_now': False},
     'photos': [{'height': 2988,
       'html_attributions': ['&lt;a href="https://maps.google.com/maps/contrib/109021919043392669000"&gt;Austin Chikwado Ofor&lt;/a&gt;'],
       'photo_reference': 'CmRaAAAA7HbCOQBhVUUOZZC6-P9I3a9BoSf5lAucLlrcBUQrOPJuKCjy2oW6iCu205Hl6h1vYBC8W50y70Mnw4owsxiQ7HfWWXSk8ZV3QMN-ObVXXdsjrZsP0NFlguInVpxJkqN7EhBPh-DsZG7xkKnzwmIJ784pGhT7Ty0D8XWfGBZh2ayHMpMsk5dwPw',
       'width': 5312}],
     'place_id': 'ChIJi5nvgOSMOxARRiBHB-xDQ7k',
     'plus_code': {'compound_code': 'G98Q+2C Lagos',
      'global_code': '6FR5G98Q+2C'},
     'rating': 4.4,
     'reference': 'ChIJi5nvgOSMOxARRiBHB-xDQ7k',
     'types': ['university', 'point_of_interest', 'establishment'],
     'user_ratings_total': 700},
  </code></pre>
  
  <p>-</p>
  
  <pre><code>data_list = data_df['geometry'][0]['location'].keys()
  
  for x in list(data_list):
      if isinstance(x, dict):
          print(x,data_list[x].values())
      else:
          print(x)
  </code></pre>