0

I made a code in php for data cleaning. Now I am trying to write the same code in python since python speed seems to be faster than php.

I have problem in one part of code, as I am not understanding, how should I write this code in python.

This is my php code. How can I write this part in python?

if(!array_key_exists("specialities",$d['data']))
{
   continue;
}

I tried the following, but its not working:-

if not "specialities" in d['data']:
   continue

and

if "specialities" not in d['data']:
   continue

Please help me with this. Thanks in advance.

This is the sample data:

"data" : {
        "website" : "something",
        "city" : "Bangalore",
        "specialties" : null,
        "description" : "",
        "zip" : "560029",
        "companyName" : "XYZ Company",
        "street1" : "SG Palya",
        "state" : "Karnataka",
    }

This data is being retrieved from mongodb in json format.

Mannu Nayyar
  • 193
  • 1
  • 5
  • 21

1 Answers1

2

Maybe the error is only a typo in the data?

Check: specialities != specialties

Your suggested solution should work:

if "specialties" not in d['data']:
    continue
Manuel Taber
  • 427
  • 5
  • 19