a=file.read()
This reads the entire file into A
so after line 4, add for line in a: state = line.strip().split() ...remove current line 5
also use more meaningful names, single letter names will get you in trouble quickly because you won't be able to remember what's what.