本帖最后由 qq1151985918 于 2021-12-2 20:41 编辑
fun = lambda x: str({i.strip() for i in x.split(",")})
with open("A.txt", "r", encoding="utf-8") as f:
setsA = list(map(fun, f.readlines()))
with open("B.txt", "r", encoding="utf-8") as g:
setsB = list(map(fun, g.readlines()))
all_sets = [eval(s) for s in set(setsA + setsB) if s]
new_sets = []
while all_sets:
s = all_sets.pop()
if any(s.issubset(x) for x in all_sets):
continue
elif any(s.issubset(y) for y in new_sets):
continue
else:
new_sets.append(s)
with open("C.txt", "w", encoding="utf-8") as h:
h.write("\n".join(map(str, new_sets)))
print("OK!")
|