below is a function that given an input word index, will return a new word index that is the same as the original word index but excludes entries from start_number through end_number.
my_dict={} #create a dictionary where the values are integers
for i in range (10):
my_dict[i]=i
# function to return a dictionary identical to input dictionary but missing entries from start_number through end_number
def dump_words(word_index, start_number, end_number):
temp_dict={}
new_dict={}
for key, value in word_index.items():
if value<start_number or value>end_number:
temp_dict[key]=value
# now renumber the values in the dictionary
for key, value in temp_dict.items():
if value<start_number:
new_dict[key]=value
else:
new_dict[key]=value-end_number
return new_dict
new_dict=dump_words(my_dict, 1, 5)
for key, value in new_dict.items():
print (key,value)
# printout shows dictionay items 0 through 4 are eliminated
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…