- 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.
推薦閱讀
- Oracle 11g從入門到精通(第2版) (軟件開發視頻大講堂)
- Linux核心技術從小白到大牛
- Apache Spark 2.x Machine Learning Cookbook
- 算法大爆炸:面試通關步步為營
- Git高手之路
- Podman實戰
- PostgreSQL 11從入門到精通(視頻教學版)
- Mastering KnockoutJS
- Android系統級深入開發
- Getting Started with Hazelcast(Second Edition)
- Linux C編程:一站式學習
- Swift 4從零到精通iOS開發
- 區塊鏈國產化實踐指南:基于Fabric 2.0
- Design Patterns and Best Practices in Java
- Processing開發實戰