I am using lambda function to make my code optimize and faster. Below I have written some function.
a = [{"objId":"5c077187fe506f8dd3589ce6","userid":"absurana","firstName":"Null","usrRole":"Software Quality User","lastName":"Null","tiles":"Potential CFD","userType":"User"},
{"objId":"5d9d7ce6fe506f11b275d01b","userid":"accheung","firstName":"Null","usrRole":"Software Quality User","lastName":"Null","tiles":"Potential CFD",,"userType":"User"},
{"objId":"5d9d7ce6fe506f11b275d01b","userid":"accheung","firstName":"Null","usrRole":"Software Quality User","lastName":"Null","tiles":"Potential CFD","userType":"User"}]
def function_apply(a):
for d in a:
if 'userid' in d:
d['UserId'] = d.pop('userid')
if 'userType' in d:
d['User Type'] = d.pop('userType')
if 'usrRole' in d:
d['Role'] = d.pop('usrRole')
if 'tiles' in d:
d['Tiles'] = d.pop('tiles')
return a
Now I want to convert same above function in lambda using map, but getting error. How could I achieve this?
lambdafunction will be faster than a named function?function) of values asdefstatements.mapfor mutational side effects.dicts in a list and modifying them in-place. Aforloop is exactly the right construct to be using here, notmap.