我想制作一个关于文本中字符位置的表格。例子:
Text = "一个苹果和一个香蕉"
Char:Positions(从 0 到 20)以及在这个位置使用了多少次
字符--> A:4101010...0-B:100000...0-C:000000...0-D:001000...0-E:000010...0-...-Z: 000000...0
怎么了?
position_list = []
i = 0
for char in range(29):
position_list.append([])
for position in range(20):
position_list[i].append(0)
i += 1
alphabet = ["a", "b", "c", "ç", "d", "e", "f", "g", "ğ", "h", "ı", "i", "j", "k", "l", "m", "n", "o", "ö", "p", "r", "s", "ş", "t", "u", "ü", "v", "y", "z"]
alphabet_index = 0
text = ["sample", "text"]
for word in text:
x = 0
for char in alphabet:
start = 0
while len(word) > start:
char_pos = word.find(char, start)
start += 1
if char_pos == -1:
break
else:
position_list[x][char_pos] += 1
x += 1
print(position_list)