【发布时间】:2020-06-01 17:21:46
【问题描述】:
我有一个字符串列表,我正在尝试遍历它并为每次迭代创建一个没有字符串的新列表。 我尝试了以下方法:
tx_list = ['9540a4ff214d6368cc557803e357f8acebf105faad677eb06ab10d1711d3db46', 'dd92415446692593a4768e3604ab1350c0d81135be42fd9581e2e712f11d82ed',....]
for txid in tx_list:
tx_list_copy = tx_list
tx_list_without_txid = tx_list_copy.remove(txid)
但每次迭代新列表都是空的。
【问题讨论】:
-
tx_list_copy = tx_list这不会生成tx_list的新副本。tx_list_copy指的是 SAME 列表对象。 -
行:
tx_list_copy = tx_list不进行复制。也许你的意思是:tx_list_copy = tx_list[:]
标签: python python-3.x string list