根据列表中的项目删除重复的嵌套列表

时间:2020-09-02 10:35:15

标签: python csv duplicates nested-lists

我有一个CSV文件,每次更新数据时,我的意思是行..现在我想做两件事,但是不能做。 如何根据此删除重复列表

输入:

[name , age , school]
[jack, 76, oxford ],
[march , 32, cfr],
[bee, 43, oi],
[jack ,15, iuy]

输出:

[name , age , school],
[jack, 76, oxford ],
[march , 32, cfr],
[bee, 43, oi]

注意:set(list)对我的情况无济于事

如您所见,第二个插孔没有添加到列表_这就是我想要的

和(第二件事)当我收到新行时现在怎么办?它会检查名称是否存在,是否会添加该新行,否则它将添加

3 个答案:

答案 0 :(得分:0)

MongockStandalone.builder()
             .setDriver(MongoCore3Driver.withDefaultLock(mongoClient, "demo"))
             .addChangeLogsScanPackage("co.my.test.persistence.changelog")
             .buildRunner()
             .execute();

我可以为您提供此信息,因为您尚未发布代码。希望这能给您一个想法。

答案 1 :(得分:0)

  1. 使用.parent { display: grid; gap: 10px; grid-template-columns: repeat(1, 300px); grid-template-rows: repeat(1, 500px); transform: rotate3d(1, 0.5, 0, 45deg) translate(50px, 50px); overflow: hidden; } .parent video { width: 300px; height: 500px; object-fit: cover; border-radius: 5px; }跟踪添加的名称
  2. 遍历列表项:
    2.1。如果未添加当前名称
    2.2。添加当前项目
    2.3。更新集
<div class="parent">
<video src="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/1080/Big_Buck_Bunny_1080_10s_5MB.mp4" loop autoplay muted></video>
</div>

输出:

set

要更新,只需检查名称是否已存在。

答案 2 :(得分:0)

第一个Csv文件包含此值:

duplicated = [  ['name' , 'age' , 'school'],
                ['jack', 76, 'oxford' ],
                ['march' , 32, 'cfr'],
                ['bee', 43, 'oi'],
                ['jack' ,15, 'iuy'],
                ['name' , 'age' , 'school']
             ]

执行此代码时

 #!/usr/bin/python3.8.2    
import csv

duplicated = []
names = []
clear = []

with open('python.csv', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        duplicated.append(row)

for i in duplicated:
    if i[0] not in names :
        names.append(i[0])

for i in duplicated:
    if i[0] in names and i not in clear :
        clear.append(i)
        names.remove(i[0])

for i in clear:
    print(i)

输出应为:

['nom', 'age', 'scholl']
['jack', '76', 'oxford']
['march', '32', 'cfr']
['bee', '43', 'oi']
['jack', '15', 'iuy']``

这就是你想要的:)