【发布时间】:2019-05-05 13:27:21
【问题描述】:
我有一个列表,其中包含已互换的重复值。例如
dataList=["john is student", "student is john", "john student is", "john is student", "alica is student", "good weather", "weather good"]
我想删除所有这些重复值,如图所示:
预期输出:
dataList=["john is student","john is student", "john is student","john is student","alica is student", "good weather", "good weather"]
我尝试使用的代码是:
for i in dataList:
first=(i.split()[0]) + i.split()[1] + i.split()[2]) in studentList
........
我陷入了形成逻辑的困境。我可以知道如何获得所需的结果
【问题讨论】:
-
您的问题不完整! ..在
"good weather"和"weather good"之间保留哪个?我猜第一个一个? -
@GrijeshChauhan:我已经在预期的输出中提到,“好天气”是我想要的。感谢您的解决方案,它有帮助。我对我的问题做了一个小更新,我想保留重复的值,我不想删除它们。给您带来的不便,我深表歉意。
标签: python regex python-3.x list data-extraction