パフォーマンス、エレガンス、可読性は「最善の方法」の要件です
私は辞書の配列を持っています:
items = [
{'id1' : 1, 'id2' : 2, 'other' : 'xxx'},
{'id1' : 1, 'id2' : 3, 'other' : 'yyy'},
{'id1' : 2, 'id2' : 4, 'other' : 'zzz'}
]
結果は次のようになります: ids = [1,2,3,4]
(id1 と id2 のリスト)
編集: このようなもの:
ids = []
for item in items:
if item.id1 not in ids:
ids.append(item.id1)
if item.id2 not in ids:
ids.append(item.id2)