python - 如何在python中按顺序从多个列表中删除重复记录

标签 python

<分区>

我有三个列表,每个列表有四个值,我必须从这三个列表中删除重复的值

这是三个列表

country_list = ['USA', 'India', 'China', 'India']
city_list = ['New York', 'New Delhi', 'Beijing', 'New Delhi']
event_list = ['First Event', 'Second Event', 'Third Event', 'Second Event']

因为它在所有三个列表中显示“India”、“new delhi”和“Second event”正在重复,这意味着它们再次相互重复。我想删除这些重复值,并希望结果如下

country_list = ['USA', 'India', 'China']
city_list = ['New York', 'New Delhi', 'Beijing']
event_list = ['First Event', 'Second Event', 'Third Event']

那么我怎样才能得到这个结果呢?有什么函数吗?

最佳答案

一种简单的方法是执行以下操作:

country_list = list(set(country_list))
city_list = list(set(city_list))
event_list = list(set(event_list))

希望这对您有所帮助。

关于python - 如何在python中按顺序从多个列表中删除重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41159674/

相关文章:

python - 函数#python的内部环境

python - 为什么 py.test 将我的 xfail 测试显示为已跳过?

python - Python的itertools.count怎么可能不增加?

Python 帮助 "from distutils.core import setup"

python - 如何惩罚决策树错误分类某个类?

python - 替换Python中括号内的所有非字母数字异常

python - 如何使用levenshtein函数删除pandas中的相似值

python - exec() 方法中自定义命名空间的子类 python 字典

python - 如何将 Pandas 日期时间列的时间更改为午夜?

python - 无法使用 pip 安装碳?