Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法在没有复制模块的情况下创建字典的深层副本?我需要复制字典 N 次,但我在一个精简了不包含copy的 Jython 库的环境中工作。我无法向该系统添加模块。
我可以将字典转换为列表并使用 [:] 进行复制,但想知道是否可以使用字典。
那么dictionary-inside-dictionary只有一层深吗?如果是这样,您可以尝试:
copy = {} for k, v in original.items(): copy[k] = dict(v)