If you want to find most occurred alphabet in a text in Python? This program will return the alphabet which is earlier in alphabetical order, If two alphabet have safe frequency.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import collections, string def occurence(text): alpha = string.lowercase text = text.lower() count = {} final = [] for x in alpha: localcount = text.count(x) count[x] = localcount max1 = max(count, key=count.get) a = count[max1] for y in count: if count[y] == a: final.append(y) return min(final) |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.