2009-10-30から1日間の記事一覧

はてな バグ

>>> for i in xrange(200): ... print i, chr(i) ... 上のコードをpythonで実行してできた文字列を はてブのcode記法に入れたら その日の日記すべての日本語がバグった。 上の記事の日本語部分を書き直すはめになった。 上で使っているchr()は文字コードから…

ドキュメンテーション文字列 __doc__

>>> import sys >>> print sys.getrefcount.__doc__ getrefcount(object) -> integer Return the reference count of object. The count returned is generally one higher than you might expect, because it includes the (temporary) reference as an arg…

2つのlistからdictを作成

>>> L1 = [1,2,3] >>> L2 = [4,5,6] >>> zip(L1, L2) [(1, 4), (2, 5), (3, 6)] >>> dict(zip(L1,L2)) {1: 4, 2: 5, 3: 6}

python list 基礎

>>> L = range(10) >>> L[::2] [0, 2, 4, 6, 8] >>> L[:] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> L[::] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> L[::3] [0, 3, 6, 9]