如果
csv_reader = csv.DictReader(csv_file)
for line in csv_reader:
if line['Title'] == ???:
,并且想要检查Title
列中每个line
(行)中的字段是否与下一个line
中紧跟其后的字段相同。为了进一步澄清:如果您认为行是x,列是y:我想检查是否(行,列)==(行+ 1,列),其中列称为Title
。我怎样才能做到这一点呢?我试着做if line['Title'] == next(line)['Title']:但是它不工作。
有很多方法可以实现它,但其中之一是
csv_reader = list(csv.DictReader(csv_file))
for i in range(len(csv_reader)-1):
if csv_reader[i]['Title'] == csv_reader[i+1]['Title']: