How to handle a dictionary value that is a list

Shaozhong SHI shishaozhong at gmail.com
Fri Oct 2 16:25:58 EDT 2020


Hi, All,

I was trying to handle the value of  "personRoles" in a part of json
dictionary.

Can anyone tell me various ways to handle this?

Regards,

Shao

"regulatedActivities": [
    {
      "name": "Accommodation for persons who require nursing or personal
care",
      "code": "RA2",
      "contacts": [
        {
          "personTitle": "Mr",
          "personGivenName": "Steven",
          "personFamilyName": "Great",
          "personRoles": [
            "Registered Manager"
          ]

e,f = [],[]
for result in d['regulatedActivities']:
    e.append(result['name'])
   #### for s in result['contacts']['personRoles']:
       #### t = (list)
        ####  print s ###f.append(s)
f = d['regulatedActivities']['contacts']['personRoles']
df1 = pd.DataFrame([e,f]).T


More information about the Python-list mailing list