article = '''This is a photograph of our village.
Our village is in a valley.
It is between two hills.
The village is on a river.
Here is another photograph of the village.
My wife and I are walking along the banks of the river.
We are on the left.
There is a boy in the water.
He is swimming across the river.
Here is another photograph.
This is the school building.
It is beside a park.
The park is on the right.
Some children are coming out of the building.
Some of them are going into the park.
'''
def get_word_count(article):
count = {}
word_list=article.lower().replace('.','').split()
for word in word_list:
if word in count:
count[word] += 1
else:
count[word] = 1
return count
print(get_word_count(article))
为啥定义的空字典但是在执行if语句时字典中已经有了内容呢?
各位大神求解!!!