我有一個獨特的(唯一鍵)字典,我更新了一些新的鍵,這取決於網頁上的數據。 ,我只想處理很長一段時間後可能出現的新密鑰。下面是一段代碼就明白了:Python - 僅處理詞典的新元素
a = UniqueDict()
while 1:
webpage = update() # return a list
for i in webpage:
title = getTitle(i)
a[title] = new_value # populate only new title obtained because it's a unique dictionnary
if len(a) > 50:
a.clear() # just to clear dictionnary if too big
# Condition before entering this loop to process only new title entered
for element in a.keys():
process(element)
有一個只知道在dictionnary(因爲大部分的時間,這將是相同的鍵和值,所以我不想增添了新的按鍵方式他們被處理)? 謝謝。
的OrderedDict只記得順序,但在我的第二個循環中,dictionnary仍在處理。例如:如果我找到2個標題,我將它們添加到詞典中,然後它們將被處理,但它在第二個循環中,這是相同的標題,它們不會被添加,但它們仍然會被處理。 – SyedElec