算法:
统计所有字母出现的次数,然后返回只出现一次的
>>> s="ab cd abcde i fgh"
>>> result=[]
>>> for i in s:
... if (i>="a" and i<="z") or (i>="A" and i<="Z"):
... if s.count(i)==1:
... result.append(i)
...
>>> print(result)
['e', 'i', 'f', 'g', 'h']
封装为一个函数
def count_one_occurence_word(s):
result=[]
for i in s:
if (i>="a" and i<="z") or (i>="A" and i<="Z"):
if s.count(i)==1:
result.append(i)
print(result)
s="ab cd abcde i fgh"
count_one_occurence_word(s)