官术网_书友最值得收藏!

  • Matplotlib 2.x By Example
  • Allen Yu Claire Chung Aldrin Yim
  • 75字
  • 2021-07-02 19:34:33

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.

主站蜘蛛池模板: 桂林市| 沅陵县| 临沂市| 新乐市| 祁连县| 滕州市| 大化| 昆山市| 琼结县| 鲜城| 通河县| 垦利县| 四川省| 呈贡县| 江华| 伊宁县| 泽州县| 临海市| 红安县| 台江县| 旬阳县| 石泉县| 石屏县| 仁布县| 建水县| 商城县| 西安市| 普兰县| 龙游县| 吴桥县| 大化| 宁明县| 东阳市| 元谋县| 杭州市| 绥阳县| 嘉荫县| 万全县| 贡觉县| 满洲里市| 堆龙德庆县|