git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to handle a dictionary value that is a list


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