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.
我有一个字符串列表存储在wk
wk
我运行以下代码。
n_wk=wk for i in range(10): if some condition: n_wk[i]='new'
我想保留这些wk值。但是,wk也随着n_wk. 谁能指出这个错误?
n_wk
创建以下副本:wk
n_wk = list(wk)
或使用:
n_wk = wk[:]
两者都将索引复制到新列表中。