2019年11月10日日曜日

開発環境

Practical Programming: An Introduction to Computer Science Using Python 3.6 (Paul Gries(著)、Jennifer Campbell(著)、Jason Montojo(著)、Pragmatic Bookshelf)のChapter 8(Storing Collections of Data Using Lists)、Exercise 8の解答を求めてみる。

コード

#!/usr/bin/env python3
import doctest


def is_longer(l1: list, l2: list) -> bool:
    '''
    >>> is_longer([1, 2, 3], [4, 5])
    True
    >>> is_longer(['abcdef'], ['ab', 'cd', 'ef'])
    False
    >>> is_longer(['a', 'b', 'c'], [1, 2, 3])
    False
    '''
    return len(l1) > len(l2)


if __name__ == '__main__':
    doctest.testmod()

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

% mypy sample8.py 
Success: no issues found in 1 source file
% ./sample8.py -v
Trying:
    is_longer([1, 2, 3], [4, 5])
Expecting:
    True
ok
Trying:
    is_longer(['abcdef'], ['ab', 'cd', 'ef'])
Expecting:
    False
ok
Trying:
    is_longer(['a', 'b', 'c'], [1, 2, 3])
Expecting:
    False
ok
1 items had no tests:
    __main__
1 items passed all tests:
   3 tests in __main__.is_longer
3 tests in 2 items.
3 passed and 0 failed.
Test passed.
%

0 コメント:

コメントを投稿

関連コンテンツ