Reputation: 21
If I have
csv_reader = csv.DictReader(csv_file)
for line in csv_reader:
if line['Title'] == ???:
and want to check if the field in each line
(row) in column Title
is the same as the field right after it in the next line
.
For extra clarification: if you consider row to be x and column to be y: I want to check if (row, column) == (row + 1, column) where column is called Title
.
How can I achieve this? I tried doing
if line['Title'] == next(line)['Title']:
but it doesn't work.
Upvotes: 0
Views: 91
Reputation: 942
there is many ways to achieve it, but one of them is this
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']:
Upvotes: 1