copyofnumbers = [1, 2, 3, 3, 1, 1, 4, 4, 5, 6, 7, 6, 7, 1]
copyofnumbers.sort()
for item in copyofnumbers:
if (copyofnumbers.count(item) > 1):
copyofnumbers.remove(item)
print(copyofnumbers)
Run Code Online (Sandbox Code Playgroud)
我正在尝试从列表中删除相同的项目。上面的代码删除所有重复的项目,但不删除“ 1”。我究竟做错了什么 ?
[1, 1, 2, 3, 4, 5, 6, 7]
Run Code Online (Sandbox Code Playgroud)
我希望输出应删除所有重复的项目。
我希望代码删除所有重复的项目。
python ×1