擅长:python、mysql、java
<p>尝试使用<a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow noreferrer">collections.Counter</a>,如下所示:</p>
<pre><code>from collections import Counter
text= "Hotel_Rooms: R15,R11,R5,R4,R8,R2,R15,R3,R6,R1,R6,R5,R3,R2,R4,R1,R2,R5,R1,R4,R3,R6,R8,R4,R3,R1,R5,R6,R2"
C = Counter(text.split('Hotel_Rooms: ')[1].split(','))
print [[k,]*v for k,v in C.items()]
</code></pre>