So if you have:
category_list = ['cc18f344-7f94-4ce5-bfde-4031b21f2bf3', '632289ec-3c62-4133-be4d-5dab9112491b', '4ea7fd7e-ea95-4fb6-a62e-9835baa43a75', '8d6bea3d-3798-449d-930f-d56cf3f5d19f']
data = '{"language_code":"en_PK","vendor_id":"btqk","include_component_types":["multi_list"],"brand":"foodpanda","country_code":"pk","offset":0,"category_id":"8d6bea3d-3798-449d-930f-d56cf3f5d19f"}'
You can simply lookup as follows:
import json
category_list.index(json.loads(data)["category_id"])
OUTPUT
3
Clearly, you need to managed situations when the category_id
is not in category_list
, and you can do it in different ways:
category_id = json.loads(data)["category_id"]
if category_id in category_list:
print(category_list.index(category_id))
or you can catch the exception:
try:
category_list.index(json.loads(data)["category_id"])
except ValueError:
# Do what you need here