def dict_strip(d):
"""Strips whitespace from the string values of the given dictionary (recursively).
Args:
d: A dictionary object.
Returns:
A new dictionary object, whose string values' whitespace has been stripped out.
"""
_d = deepcopy(d)
for k, v in iteritems(d):
if isinstance(v, str):
_d[k] = v.strip()
elif isinstance(v, dict):
_d[k] = dict_strip(v)
return _d
评论列表
文章目录