str =input("I am a student,and you are a teacher")
resoult = {}
for i in str
resoult[i] = str.count(i)
print(resoult)
我写的这个,但是第三行显示语法错误,想问问什么情况呀。那这道题怎么写呀
s ="I am a student,and you are a teacher"
s = s.replace(",", " ")
resoult = {}
for i in s.split():
resoult[i] = s.count(i)
print(resoult)
"""--result
{'I': 1, 'am': 1, 'a': 6, 'student': 1, 'and': 1, 'you': 1, 'are': 1, 'teacher': 1}
"""
count = str.split(' ')