put a key in dictionary into another key and remove it from dictionary:
Idiots way:
Tech C**P way:
#pop #python #dictionary #code_improvement
Idiots way:
data = {
'username': 'alireza@gmail.com'
}
data['email'] = data['username']
del data['username']
Tech C**P way:
data = {
'username': 'alireza@gmail.com'
}
data['email'] = data.pop('username')
pop
access the data and remove it from data payload. In case username
is not in data, an error will be raised. To prevent such an error give it default value:data['email'] = data.pop('username', 'NO_USERNAME')
#pop #python #dictionary #code_improvement