開発環境
- macOS Catalina - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 10(Reading and Writing Files)、Exercise 2の解答を求めてみる。
コード
#!/usr/bin/env python3
import pprint
from typing import List, Tuple
filename = 'alkaline_metals.txt'
list_of_lists: list = []
with open(filename) as f:
for line in f:
name, number, weight = line.strip().split()
list_of_lists.append([name, int(number), float(weight)])
pprint.pprint(list_of_lists)
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% mypy sample2.py
Success: no issues found in 1 source file
% ./sample2.py
[['beryllium', 4, 9.012],
['magnesium', 12, 24.305],
['calcium', 20, 20.078],
['strontium', 38, 87.62],
['barium', 56, 137.327],
['radium', 88, 226.0]]
%
0 コメント:
コメントを投稿