I have a parent dictionary
parent = [
{
"user": "a@gmail.com",
"type": "Product Team",
"message": "Developer",
"employeeId": 101
},
{
"user": "b@gmail.com",
"type": "Product Team",
"message": "Developer",
"employeeId": "102"
}
]
My input is
body = {"employeeId":102}
My input will vary for testing
body = {"employeeId":101}
body = {"employeeId":103}
I have search in parent dictionary and retrieve the user
employeeId
and message
if it matches employeeId
- I need to iterate over the parent dictionary
- once I found the first match then i have to break out from the loop
- if not i need to continue the loop
- if success i need to return a dictionary
- if
employeeId
doesnot match in parent dict then it should say employeeId doesnot exist
My code is below
def noid():
return "No ID"
def new_f():
for conf in parent :
if int(conf["employeeId"]) == int(body['employeeId']):
user = conf['user']
employeeId= conf["employeeId"]
message = conf["message"]
return {'user': user, 'employeeId': employeeId, 'message': message}
break
else:
continue
return noid()
new_f()
In my code only employeeId:101
is working only for first element is working./ Only first dictionary getting success