Q:

Separating columns from a file by last column

I'm trying to do this: if the last column is negative number from 1-5 then write second and last column to a file "neg.txt". If a last column is positive number, second and last column need to be written to "pos.txt". My both output files end up empty after execution. I don't know what's wrong with the code, when I think if statement can handle multiple conditions. I also tried with regular expressions but it did't work so I made it as simple as possible to see what is not working.
The input file looks like this:
abandon     odustati         -2
abandons      napusta     -2
abandoned    napusten   -2
absentee    odsutne       -1
absentees   odsutni          -1
aboard      na brodu     1
abducted     otet       -2
accepted         prihvaceno 1

My code is:
from urllib.request import urlopen
import re

pos=open('lek_pos.txt','w')
neg=open('lek_neg.txt','w')

allCondsAreOK1 = ( parts[2]=='1' and parts[2]=='2' and
             parts[2]=='3' and parts[2]=='4' and parts[2]=='5' )

allCondsAreOK2 = ( parts[2]=='-1' and parts[2]=='-2' and
             parts[2]=='-3' and parts[2]=='-4' and parts[2]=='-5' )

with open('leksicki_resursi.txt') as pos:
    for line in pos:
        parts=line.split()  # split line into parts
        if len(parts) > 1: # if at least 2 columns (parts)
            if allCondsAreOK:
                pos.write(parts[1]+parts[2])
            elif allCondsAreOK2:
                neg.write(parts[1]+parts[2])
        else:
            print("nothing matches")

A:

You don't need a regex, you just need an if/elif checking if after casting to int the last value falls between -5 and -1, if it does you write to the neg file or if the value is any non negative number you write to the pos file:
with open('leksicki_resursi.txt') as f,  open('lek_pos.txt','w')as pos, open('lek_neg.txt','w') as neg:
    for row in map(str.split, f):
        a, b = row[1], int(row[-1])
        if b >= 0:
            pos.write("{},{}\n".format(a, b))
        elif -5 <= b <= -1:
            neg.write("{},{}\n".format(a, b))

If the positive nums must also be between 1-5 then you can do something similar to the negative condition:
    if 5 >= int(b) >= 0:
         pos.write("{},{}\n".format(a, b))
    elif -5 <= int(b) <= -1:
         neg.write("{},{}\n".format(a, b))

Also if you have empty lines you can filter them out:
  for row in filter(None,map(str.split, f)):

