擅长:python、mysql、java
<p>您可以使用一些标准库来让您的生活更轻松</p>
<pre><code>import collections
import re
# Open the file
with open("./file.txt", 'r') as f:
txt = f.read()
# Find all the alphabetic characters
letters = re.findall("[a-zA-Z]", txt)
# Count them
counts = collections.Counter(letters)
# Print the star histogram
for i in 'abcdefghijklmnopqrstuvwxyz':
if i in counts:
print(f"{i} | {'*' * counts[i]}")
else: print(f"{i} | ")
</code></pre>