- 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.
推薦閱讀
- Visual Basic學(xué)習(xí)手冊
- The Professional ScrumMaster’s Handbook
- Natural Language Processing with Java and LingPipe Cookbook
- 3ds Max印象 電視欄目包裝動畫與特效制作
- BeagleBone Robotic Projects(Second Edition)
- Python期貨量化交易實(shí)戰(zhàn)
- Mastering Adobe Captivate 7
- Android應(yīng)用開發(fā)實(shí)戰(zhàn)(第2版)
- HTML5游戲開發(fā)實(shí)戰(zhàn)
- Oracle Database 12c DBA官方手冊(第8版)
- C語言進(jìn)階:重點(diǎn)、難點(diǎn)與疑點(diǎn)解析
- Python Business Intelligence Cookbook
- Python數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第2版)
- 自己動手做智能產(chǎn)品:嵌入式JavaScript實(shí)現(xiàn)
- Python程序設(shè)計教程