擅长:python、mysql、java
<p>使用<a href="https://docs.python.org/3.3/library/collections.html?highlight=counter#collections.Counter" rel="nofollow noreferrer">Counter</a></p>
<pre><code>from collections import Counter
name_vote = Counter()
count = int(input('How many? '))
while count >= 1:
name = input('Name ')
vote = int(input('Vote '))
name_vote += {name: vote}
count -= 1
for name, cnt in name_vote.items():
print("Name: {}, Vote: {}".format(name, cnt))
</code></pre>