優先度付きの優先キュー(heapq
)を使用しdatetime.datetime
ています。
検索するstartTimeとendTimeがある場合、このリストから要素のサブセットを抽出するための最もPython的な方法は何ですか。(元のリストを変更できないため、新しいリストを作成して返すか、イテレータを返す必要があります)
以下は私が持っているものの例です:
>>> import heapq
>>> timeLine = []
>>> from datetime import datetime
>>> heapq.heappush(timeLine, (datetime.now(),'A'))
>>> heapq.heappush(timeLine, (datetime.now(),'B'))
>>> heapq.heappush(timeLine, (datetime.now(),'C'))
>>> timeLine
[(datetime.datetime(2013, 2, 8, 15, 25, 14, 720000), 'A'), (datetime.datetime(2013, 2, 8, 15, 25, 30, 575000), 'B'), (datetime.datetime(2013, 2, 8, 15, 25, 36, 959000), 'C')]
実際のアプリケーションリストは膨大です。