pythonでuniq
id:gi-chiさんのエントリを読んで
Rubyにはuniqがあるんだと知りました。
配列操作の比較表 Ruby, Java5, Python - 制作日誌ギーチ!
それpy!ということで、これが速いでしょうか。
def uniq(seq):
seen = set()
return [x for x in seq if x not in seen and not seen.add(x)]
こちらのサイトに検証記事とテストプログラムがあります。
Fastest way to uniqify a list in Python - Peterbe.com
From the comments I've now added a couple of more functions to the benchmark. Some which don't support uniqify a list of objects that can't be hashed unless passed with a special hashing method. So see all the functions download the file
Here are the new results:
(f2 and f4) were too slow for this testdata.
関連:
重複なしリスト - 鯨飲馬食コード
pythonでuniq - pyletの日記
重複なしリストの作り方(いわゆるuniq) - 図書館断想