If order does not matter, you can use foo = "mppmt" "".join(set(foo)) set() will create a set of unique letters in the string, and "".join() will join the letters back to a string in arbitrary order. If order does matter,…
#统计字符串中每个字符出现的次数 以The quick brown fox jumps over the lazy dog为例 message='The quick brown fox jumps over the lazy dog' count={} for character in message: count.setdefault(character,0) count[character]=count[character]+1 print(count) 参考:<Python编程快速上手--…
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: if not ('\u4e00' <= c <= '\u9fa5'): return False return True…