3 ms·
Wouldn't it be more intuitive to do the following in example 2? def post_process(data): newdict = data.copy() Str = 'df_use_percent' if Str in ne
by JeanPierre 17y ago
Wouldn't it be more intuitive to do the following in example 2?
def post_process(data):
newdict = data.copy()
Str = 'df_use_percent'
if Str in newdict:
newdict[Str] = newdict[Str].rstrip('%')
return newdict
- andrewcooke 17y agoyes. (also, newdict = dict(data) seems more natural to me since the same idiom can be used for copying lists, which don't have a copy method).