2014年7月31日木曜日

開発環境

Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 5(Making Choices)、5.6(Exercises) 6.を解いてみる。

5.6(Exercises) 6.

コード(BBEdit)

sample6.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

def different(a, b):
    return a == b

l = [1, 2, 3, 4, 5, 'a', 'b', 'c', 'd', 'e', '1', '2', '3', '4', '5']
for a, b in [(a, b) for a in l for b in l]:
    print('{0} == {1}: {2}'.format(repr(a),repr(b), different(a, b)))

入出力結果(Terminal, IPython)

$ ./sample6.py 
1 == 1: True
1 == 2: False
1 == 3: False
1 == 4: False
1 == 5: False
1 == 'a': False
1 == 'b': False
1 == 'c': False
1 == 'd': False
1 == 'e': False
1 == '1': False
1 == '2': False
1 == '3': False
1 == '4': False
1 == '5': False
2 == 1: False
2 == 2: True
2 == 3: False
2 == 4: False
2 == 5: False
2 == 'a': False
2 == 'b': False
2 == 'c': False
2 == 'd': False
2 == 'e': False
2 == '1': False
2 == '2': False
2 == '3': False
2 == '4': False
2 == '5': False
3 == 1: False
3 == 2: False
3 == 3: True
3 == 4: False
3 == 5: False
3 == 'a': False
3 == 'b': False
3 == 'c': False
3 == 'd': False
3 == 'e': False
3 == '1': False
3 == '2': False
3 == '3': False
3 == '4': False
3 == '5': False
4 == 1: False
4 == 2: False
4 == 3: False
4 == 4: True
4 == 5: False
4 == 'a': False
4 == 'b': False
4 == 'c': False
4 == 'd': False
4 == 'e': False
4 == '1': False
4 == '2': False
4 == '3': False
4 == '4': False
4 == '5': False
5 == 1: False
5 == 2: False
5 == 3: False
5 == 4: False
5 == 5: True
5 == 'a': False
5 == 'b': False
5 == 'c': False
5 == 'd': False
5 == 'e': False
5 == '1': False
5 == '2': False
5 == '3': False
5 == '4': False
5 == '5': False
'a' == 1: False
'a' == 2: False
'a' == 3: False
'a' == 4: False
'a' == 5: False
'a' == 'a': True
'a' == 'b': False
'a' == 'c': False
'a' == 'd': False
'a' == 'e': False
'a' == '1': False
'a' == '2': False
'a' == '3': False
'a' == '4': False
'a' == '5': False
'b' == 1: False
'b' == 2: False
'b' == 3: False
'b' == 4: False
'b' == 5: False
'b' == 'a': False
'b' == 'b': True
'b' == 'c': False
'b' == 'd': False
'b' == 'e': False
'b' == '1': False
'b' == '2': False
'b' == '3': False
'b' == '4': False
'b' == '5': False
'c' == 1: False
'c' == 2: False
'c' == 3: False
'c' == 4: False
'c' == 5: False
'c' == 'a': False
'c' == 'b': False
'c' == 'c': True
'c' == 'd': False
'c' == 'e': False
'c' == '1': False
'c' == '2': False
'c' == '3': False
'c' == '4': False
'c' == '5': False
'd' == 1: False
'd' == 2: False
'd' == 3: False
'd' == 4: False
'd' == 5: False
'd' == 'a': False
'd' == 'b': False
'd' == 'c': False
'd' == 'd': True
'd' == 'e': False
'd' == '1': False
'd' == '2': False
'd' == '3': False
'd' == '4': False
'd' == '5': False
'e' == 1: False
'e' == 2: False
'e' == 3: False
'e' == 4: False
'e' == 5: False
'e' == 'a': False
'e' == 'b': False
'e' == 'c': False
'e' == 'd': False
'e' == 'e': True
'e' == '1': False
'e' == '2': False
'e' == '3': False
'e' == '4': False
'e' == '5': False
'1' == 1: False
'1' == 2: False
'1' == 3: False
'1' == 4: False
'1' == 5: False
'1' == 'a': False
'1' == 'b': False
'1' == 'c': False
'1' == 'd': False
'1' == 'e': False
'1' == '1': True
'1' == '2': False
'1' == '3': False
'1' == '4': False
'1' == '5': False
'2' == 1: False
'2' == 2: False
'2' == 3: False
'2' == 4: False
'2' == 5: False
'2' == 'a': False
'2' == 'b': False
'2' == 'c': False
'2' == 'd': False
'2' == 'e': False
'2' == '1': False
'2' == '2': True
'2' == '3': False
'2' == '4': False
'2' == '5': False
'3' == 1: False
'3' == 2: False
'3' == 3: False
'3' == 4: False
'3' == 5: False
'3' == 'a': False
'3' == 'b': False
'3' == 'c': False
'3' == 'd': False
'3' == 'e': False
'3' == '1': False
'3' == '2': False
'3' == '3': True
'3' == '4': False
'3' == '5': False
'4' == 1: False
'4' == 2: False
'4' == 3: False
'4' == 4: False
'4' == 5: False
'4' == 'a': False
'4' == 'b': False
'4' == 'c': False
'4' == 'd': False
'4' == 'e': False
'4' == '1': False
'4' == '2': False
'4' == '3': False
'4' == '4': True
'4' == '5': False
'5' == 1: False
'5' == 2: False
'5' == 3: False
'5' == 4: False
'5' == 5: False
'5' == 'a': False
'5' == 'b': False
'5' == 'c': False
'5' == 'd': False
'5' == 'e': False
'5' == '1': False
'5' == '2': False
'5' == '3': False
'5' == '4': False
'5' == '5': True
$

0 コメント:

コメントを投稿