def deepCopy(pa):
if isinstance(pa, dict):
return {k: deepCopy(v) for k, v in pa.items()}
elif isinstance(pa, list):
return [deepCopy(item) for item in pa]
elif isinstance(pa, tuple):
return tuple([deepCopy(item) for item in pa])
else:
return pa
if __name__ == '__main__':
lt = [1, 2, 3, 6, 4,([5, 6, 8, 7, [7, 8, {"test": 123456, "ok": "odgjegmgddhjd", "v50": 23568}, 5, 9, 7]], (7, 4, {"tup": 8}))]
print(deepCopy(lt))
###结果:[1, 2, 3, 6, 4, ([5, 6, 8, 7, [7, 8, {'test': 123456, 'ok': 'odgjegmgddhjd', 'v50': 23568}, 5, 9, 7]], (7, 4, {'tup': 8}))]
python 实现深拷贝
最新推荐文章于 2024-04-12 11:10:13 发布