擅长:python、mysql、java
<p>您应该使用defaultdict(默认值为空列表)并在遍历字符串时更新索引列表:</p>
<pre><code>from collections import defaultdict
string = str(raw_input())
occurences = defaultdict(list)
for i, c in enumerate(string):
occurences[c].append(i)
print occurences
</code></pre>
<p>然后使用列表理解获得事件列表:</p>
<pre><code>occurences = [l for l in occurences.values()]
</code></pre>