TEwrc
2020-12-25 15:31:23 +08:00
写了半天好像对了:
import csv
from itertools import tee, takewhile, islice
result = []
with open('test.csv', 'r') as f:
info1, info2, info3 = tee(islice(csv.reader(f), 1, None), 3)
sorted_by_date1 = sorted(info1, key=lambda x: x[2], reverse=True)
sorted_by_date2 = takewhile(lambda x: x[3], sorted(info2, key=lambda x: x[3], reverse=True))
for j in sorted_by_date2:
if j[0] not in [i[0] for i in result]:
result.append(j)
for k in sorted_by_date1:
if k[0] not in [i[0] for i in result]:
result.append(k)
print(result)