Python Day4

Wordcount

def wordcount(a):
   text = a.readlines()
   count = {}   #存字典
   for line in text:
       marks = line.strip().split(' ')   #strip() 首尾去空格
       for mark in marks:
           if mark not in count:
               count[mark] = 1
           else:
               count[mark] +=1
   return count

你可能感兴趣的:(Python Day4)