Mannu Nayyar Mannu Nayyar - 2 months ago 19
PHP Question

Convert php !array_key_exists to python

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?


I tried the following, but its not working:-

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


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

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.


Maybe the error is only a typo in the data?

Check: specialities != specialties

Your suggested solution should work:

if "specialties" not in d['data']: