import re
with open('C:\\Users\\fxylo\\Downloads\\C2.txt', 'r', encoding='utf-8') as f:
data = f.readlines()
new_data = []
for item in data:
item = item.strip()
sorted_item = sorted(re.sub(r'[{|}]', '', item).split(','))
new_data.append(','.join(sorted_item))
for index, item in enumerate(new_data):
if ',' in item and (item in new_data[0:index] or item in new_data[index + 1:]):
data[index] = '待删项——' + data[index]
with open('C:\\Users\\fxylo\\Downloads\\B.txt', 'w', encoding='utf-8') as f:
f.writelines(data)
这个也许可以 |