Matplotlib 2.x By Example
上QQ阅读APP看书,第一时间看更新

The basic Python way

We can initialize an empty list, read the file line by line, split each line, and append the second element to our list:

evens = []
with open as f:
for line in f.readlines():
evens.append(line.split()[1])

Of course, you can also do this in a one-liner:

evens = [int(x.split()[1]) for x in open('evens.txt').readlines()]

We are just trying to go step by step, following the Zen of Python: simple is better than complex.