2007-06-22から1日間の記事一覧

整数とビット列の相互変換

ref:http://www.nishiohirokazu.org/pwe2007/2007/06/post_7.html Python って関数型言語ですよね。 ちなみに、変換数値の上限がない代わりに負数非対応。というか Python は自動的に数値の範囲を拡張するからちゃんとやろうとするとかなり面倒そう。 import…

名簿の並び替え

ref:http://www.nishiohirokazu.org/pwe2007/2007/06/post_5.html 適当にオプションで切り替えられるように。そしてファイルの入出力は UNIX 流儀で。 import sys, fileinput class Person(object): __slots__ = 'firstname lastname'.split() def __init__(…

バッファ大杉

ふと、electric-buffer-list で開いている buffer の数を数えてみたら Dired の buffer も含めて 66 個あった。screen の上で立ち上げっぱなしとはいえ、開き過ぎだろ。

sum と reduce

今日、list に対しても sum が使えることに気づいた。ということは以下の2つは等価だ。 import operator reduce(operator.add, [[1, 2, 3], [4, 5, 6], [7, 8, 9]], []) sum([[1, 2, 3], [4, 5, 6], [7, 8, 9]], []) じゃあ __add__ が定義されていればなん…

行列の回転

ref:http://www.nishiohirokazu.org/pwe2007/2007/06/post_4.html ひたすら手続き的な記述をさけてみる。 def rotater(matrix): """ rotate matrix >>> rotater([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) [[7, 4, 1], [8, 5, 2], [9, 6, 3]] """ return [list(row…

Suffix Array の効率は考慮していない

ref:http://asip.tdiary.net/20070621.html#p04 ref:http://4topcoder.blogspot.com/2007/03/suffix-array_27.html ASIPさんが「効率をある程度考慮した Suffix Array」としてクリップしているようですが、これ、誤解しているんじゃないだろうか。 件のペー…