Je veux faire un tableau des positions des caractères dans un texte. Exemple :
Texte = " une pomme et une banane ".
Char:Positions (de 0 à 20) et combien de fois utilisé dans ces positions.
Characters--> A:4101010...0-B:100000...0-C:000000...0-D:001000...0-E:000010...0-...-Z:000000...0
Qu'est-ce qui ne va pas ?
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)