Split by tab while Remove Corrupted Data

with open(“C:/Users/user/Documents/Python/Data/sentiment labelled sentences/amazon_cells_labelled.txt”, “r”) as text_file:
lines = text_file.read().split(’\n’)

lines = [line.split("\t") for line in lines if len(line.split("\t"))==2 and line.split("\t")[1]<>’’]

File “”, line 2
lines = [line.split("\t") for line in lines if len(line.split("\t"))==2 and line.split("\t")[1]<>’’]
^
SyntaxError: invalid syntax

Hi Mriepe Lab,

“lines = text_file.read().split(’\n’)”

That is probably better written as:

lines = text_file.readlines()

“lines = [line.split(”\t") for line in lines if len(line.split("\t"))==2
and line.split("\t")[1]<>’’]"

The syntax error prints a caret ^ pointing at its best guess of where
the problem is. Syntax errors are sometimes tricky for the interpreter
to work out what the problem is, but here it can work out exactly where
the error is.

The caret is pointing at the <> symbol. This is not legal in Python 3,
you have to change it to != instead.

That worked thanks for your assistance Steven