Check the duplicate data and the number of occurrences in the list

Due to the company's business needs, it is necessary to find the same file name in the folder (regardless of the file format)

# -*- coding:utf-8 -*-
from collections import Counter

fileNameList = [_.split('.')[0] for _ in os.listdir(html_path)]
b = dict(Counter(fileNameList))
pic_htm = [key for key, value in b.items() if value > 1]
htm = [key for key, value in b.items() if value < 2]
print(pic_htm)
print(htm)

The result is as follows:

print(b)
>>>{'011001900611_86708255': 2, '01100200011112597759': 1, '20200409193519_582hkn4qlu': 2, '20200508090807109': 2}
print(pic_htm)
>>>['011001900611_86708255', '20200409193519_582hkn4qlu', '20200508090807109']
print(htm)
>>>['01100200011112597759']

 

Guess you like

Origin blog.csdn.net/weixin_43124425/article/details/108345212