大きな2次元リストをループしたい:
authors = [["Bob", "Lisa"], ["Alice", "Bob"], ["Molly", "Jim"], ... ]
著者に出現するすべての名前を含むリストを取得します。
リストをループするとき、既に見た名前を格納するためのコンテナが必要です。リストと dict のどちらを使用するべきか迷っています。
リスト付き:
seen = []
for author_list in authors:
for author in author_list:
if not author in seen:
seen.append(author)
result = seen
口述で:
seen = {}
for author_list in authors:
for author in author_list:
if not author in seen:
seen[author] = True
result = seen.keys()
どちらが速いですか?またはより良い解決策はありますか?