擅长:python、mysql、java
<p>我建议把这个问题分成三个部分:把你的字母表整理一下,然后把它写进一个文件里。请注意,下面代码中的第一行应该位于python文件的顶部,以允许您在源代码中使用utf-8字符。在</p>
<pre><code># -*- coding: utf-8 -*-
import codecs # To write UTF-8 characters to a file
import random
# Assemble data list
letters = [u'அ', u'ம', u'த']
data = [] # This list will hold the shuffled data
for current_letter in letters:
# Choose how many times to repeat the current letter.
times_repeated = random.choice([20, 30, 40])
data.extend([current_letter] * times_repeated)
# Now, shuffle the 'data' list
random.shuffle(data)
# Now write the shuffled list to a file as one continuous string
data_string = "".join(data)
with codecs.open("data.txt", "w", "utf-8") as f:
f.write(data_string)
</code></pre>
<p>请注意,如果您知道希望每个字母出现多少次,您可以将这些信息放入字典中,而不是从<code>[20, 30, 40]</code>中随机选择:</p>
^{pr2}$