jeudi 11 juin 2020

how to check the previous row in a 2D array? in Python

Suppose that I have a tsv file (named "tsv-test.txt") with the following contents:

5ig7    G   H   0   I
5ig7    A   B   0   C
5ig7    D   E   0   F
5ig7    J   K   0   L
6ch8    D   E   0   B

In the first column, I want to check if the previous row has the same term. I've read the tsv into a list as a 2D array. how do I loop through the 2D array to do this check at every row? For reference, here's what I've done so far:

import csv

#read the tsv into python, tell python its a tsv
tsv_file = open("tsv-test.txt")
read_tsv = csv.reader(tsv_file, delimiter="\t")

#put tsv into a 2D array
arraytest = []
for line in read_tsv:
    arraytest.append(line)

Aucun commentaire:

Enregistrer un commentaire