엄청난 양의 데이터 더미에 대한 표준 접근 방식이 이에 해당합니다.
여기서 list_1은 "마스터"(중복 없음)이고 list_2는 중복 된 "업데이트"라고 가정합니다.
iter_1 = iter(sorted(list_1)) # Essentially SELECT...ORDER BY
iter_2 = iter(sorted(list_2))
eof_1 = False
eof_2 = False
try:
item_1 = iter_1.next()
except StopIteration:
eof_1= True
try:
item_2 = iter_2.next()
except StopIteration:
eof_2= True
while not eof_1 and not eof_2:
if item_1 == item_2:
# do your update to create the new master list.
try:
item_2 = iter_2.next()
except StopIteration:
eof_2= True
elif item_1 < item_2:
try:
item_1 = iter_1.next()
except StopIteration:
eof_1= True
elif item_2 < item_1:
# Do your insert to create the new master list.
try:
item_2 = iter_2.next()
except StopIteration:
eof_2= True
assert eof_1 or eof_2
if eof_1:
# item_2 and the rest of list_2 are inserts.
elif eof_2:
pass
else:
raise Error("What!?!?")
예, 잠재적 인 정렬이 포함됩니다. list_1을 파일 시스템에 다시 쓸 때 정렬 된 순서로 보관하면 상당한 시간을 절약 할 수 있습니다. list_2가 정렬 된 구조에 누적 될 수 있으면 상당한 시간을 절약 할 수 있습니다.
미안하지만, 어떤 반복자가 StopIteration
을 발생 시켰는지 알아야하기 때문에, 큰 낡은 블록에서 루프 전체를 감싸고있을 수는 없습니다.
각 개체에 대해 해시를 계산하고 저장 하시겠습니까? – FogleBird