2014年10月16日木曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅲ.(Statements and Syntax)、Chapter 15.(The Documentation Interlude)、Test Your Knowledge: Quiz 3.を解いてみる。

その他参考書籍

Test Your Knowledge: Quiz 3.

コード(BBEdit)

sample3.py

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

# built-in functionのdirを使えばいい。
# 引数に渡すのは、名前でも、直接でもどちらでも可能。
# listのattributes(__で始まるattributesは除外)
attributes1 = filter(lambda a: not a.startswith('__'), dir(list))
attributes2 = filter(lambda a: not a.startswith('__'), dir([]))

list1 = list(attributes1)
list2 = list(attributes2)

print(list1)
print(list2)
print(list1 == list2)

入出力結果(Terminal, IPython)

$ ./sample3.py
['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
True
$

0 コメント:

コメントを投稿