Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 计数字母并显示在列表中
我是 python 新手。我想通过将字符串拆分为字符串中字母的唯一出现次数来创建一个列表。举个例子:google会被拆分成g oo g l e
什么是最好的方法?谢谢!
How about this:
>>> from itertools import groupby >>> strs="google" >>> " ".join("".join(g) for k,g in groupby(strs)) 'g oo g l e'