这可行:
data = [] target = [] with open('faban.txt') as fobj: for line in fobj: row = line.split() data.append(row[:-1]) target.append(row[-1])
现在:
>>> data [['faban', '1', '0', '0.288'], ['faban', '2', '0', '0.243'], ['simulated', '1', '0', '0.159'], ['faban', '1', '1', '0.189']] >>> target ['withspy', 'withoutspy', 'withoutspy', 'withoutspy']