+ 1

Getting percentage of letters in text

for char in "abcdefghijklmnopqrstuvwxyz": perc = 100 * count_char(text, char) / len(text) print("{0} - {1}%".format(char, round(perc, 2))) can someone explain this ?

27th Jul 2020, 4:44 AM
Deepak Bastakoti
Deepak Bastakoti - avatar
2 odpowiedzi
+ 2
Look at "More Types" chapter and then to "Text Analyzer", there's an explanation about how that works ... https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2457/
27th Jul 2020, 5:57 AM
Ipang
+ 1
Assuming text="abcdef....wxyz" and that count_char is a function that counts the amount of "char" in "text", then your code is computing the usage percentage of "char" in "text" and returning a formatted string for every char and the rounded percentage up to 2 decimal points. Example: Input: 'abca' Output: 'a - 50%' 'b - 25%' 'c - 25%' 'a - 50%'
27th Jul 2020, 5:01 AM
David Rios
David Rios - avatar