開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
Head First はじめてのプログラミング ―頭とからだで覚えるPythonプログラミング入門 (Eric Freeman(著)、嶋田 健志(監修)、木下 哲也(翻訳)、株式会社オライリー・ジャパン)を8章(再帰と辞書 - 反復とインデックスを超えて)の自分で考えてみよう(371ページ)の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3
import math
from unittest import TestCase, main
from typing import List
class MyTestCase(TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
max_value: int = math.inf
for name, attr in users.items():
friends: List[str] = attr['friends']
n: int = len(friends)
if n < max_value:
most_anti_social: str = name
max_value = n
self.assertEqual(n, 1)
users = {
'Kim': {
'age': 27,
'friends': ['John', 'Josh']
},
'John': {
'age': 24,
'friends': ['Kim', 'Josh'],
},
'Josh': {
'age': 32,
'friends': ['Kim']
},
}
if __name__ == '__main__':
main()
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
$ ./sample4.py . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK $
0 コメント:
コメントを投稿