且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从列表中删除所有重复项

更新时间:2023-02-18 09:14:40

只要创建一个新列表即可,如果您列表中的项目尚未在新列表中输入,否则只需继续执行下一个项目即可.您的原始列表.

Just make a new list to populate, if the item for your list is not yet in the new list input it, else just move on to the next item in your original list.

for i in mylist:
  if i not in newlist:
    newlist.append(i)

我认为这是正确的语法,但是我的python有点不稳定,我希望您至少能理解.

I think this is the correct syntax, but my python is a bit shaky, I hope you at least get the idea.