擅长:python、mysql、java
<p>一种可能的解决方案是将字符串转换为数字,并使用数字来增加数组中的值。代码可以如下:</p>
<pre><code>import numpy as np
def alph_to_num(alph):
return ord(alph.lower())-97
string='alsblnasdglasdaoerngeaglbneronbiwernblnerl'
array=np.zeros(26)
for alph in string:
index=alph_to_num(alph)
array[index]=array[index]+1
print(array)
</code></pre>
<p>它给出:<code>[5. 4. 0. 2. 5. 0. 3. 0. 1. 0. 0. 6. 0. 6. 2. 0. 0. 4. 3. 0. 0. 0. 1. 0.
0. 0.]</code></p>
<p>这里我已经做了长度为26的数组,因为你知道它只是小写英文字母。这也意味着更容易解释结果列表。你知道吗</p>