ptval = { 'H_':'001', 'He':'002', 'Li':'003', 'Be':'004', 'B_':'005' ...(you get the point) } fileHandle = open ('input.txt', 'r') for x in fileHandle: x=x.strip() if x in ptval: print ptval[x]