用Python语言写下面这道题,非常感谢

 

sentence = input()
# sentence = 'hello world nihao world hey hello java world hi python yeoman word'
#先把字符串分割成单个单词列表
list1 = sentence.split() 
#['hello', 'world', 'nihao', 'world', 'hey', 'hello', 'java', 'world', 'hi', 'python', 'yeoman', 'word']
print list1 

#把列表转为结合,为了去除重复的项
set1 = set(list1)   
#set(['java', 'python', 'word', 'nihao', 'hey', 'yeoman', 'hi', 'world', 'hello'])
print set1  

#把集合转为列表,集合元素没有顺序,没有索引属性,而列表有
list2 = list(set1)  
#['java', 'python', 'word', 'nihao', 'hey', 'yeoman', 'hi', 'world', 'hello']
print list2 

#新建一个空的字典
dir1 = {}

for x in range(len(list2)): 
    dir1[list2[x]] = 0  #字典值初始为0
    for y in range(len(list1)):
        if list2[x] == list1[y]:
            dir1[list2[x]] += 1

这题问题有点绕吧!  要是一段英文没有分隔符 !如歌判断是单词呢?

 

统计 x 出现的次数还可以! 按照 要求的 输入:ChinadailyprovidingnewsbusinessinformationBBSlearningmaterialsheWebsithaschannelsasChina, BizChina

您给断断出现多次次单词呢