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

  • 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.

主站蜘蛛池模板: 尚义县| SHOW| 平舆县| 神池县| 珲春市| 宿州市| 平陆县| 于田县| 屏山县| 安陆市| 尉氏县| 饶河县| 旅游| 公安县| 方山县| 山西省| 丰原市| 丹江口市| 武安市| 栖霞市| 喜德县| 姜堰市| 五常市| 巫溪县| 滕州市| 澄城县| 南陵县| 彝良县| 南皮县| 凤阳县| 永州市| 行唐县| 汕头市| 瑞丽市| 义乌市| 沅江市| 凯里市| 潍坊市| 兰溪市| 永嘉县| 钟祥市|