I have one function attrmapper
. The purpose for this function is to build a dictionary, information
, as attribution for the object. Is there a better way for me to rewrite the obj.information.update(
part? The part to update information attribution will be more clear? Because if we replace mapping to a long string, the function will be really hard to read.
mapping = {
'firstname': 'this is fisrt name: {} should be string',
'lastname': 'this is last name: {} should be string',
'address': 'this is address {} should be address1, address2, state, state and zipcode',
'phone_number': 'this is phone number {} should be 0 to 9',
'gender': 'this is gender {}: should be male or female',
'company': 'this is company {} should be start with G',
'position': 'this is position {} should be engineer, manager and level',
'aAbreu': 'Albert Abreu',
'cGreen': 'Chad Green',
'lCessa': 'Luis Cessa',
'aJudge': 'Aaron Judge',
'jEllsbury': 'Jacoby Ellsbury',
}
def attrmapper(obj: object) -> object:
information = {}
for name in ['aAbreu', 'cGreen', 'lCessa', 'aJudge', 'jEllsbury']:
obj.information.update(
{'{}_firstname'.format(name): mapping.get('firstname').format(mapping.get(name)),
'{}_lastname'.format(name): mapping.get('lastname').format(mapping.get(name)),
'{}_address'.format(name): mapping.get('address').format(mapping.get(name)),
'{}_phone_number'.format(name): mapping.get('phone_number').format(mapping.get(name)),
'{}_company'.format(name): mapping.get('company').format(mapping.get(name)),
'{}_position'.format(name): mapping.get('firstname').format(mapping.get(name))})
return obj