11 ms·
My Python answer for the second question, where `post` is patrio11's post as input: from collections import defaultdict from string import ascii_lette
by BioGeek 16y ago
My Python answer for the second question, where `post` is patrio11's post as input:
from collections import defaultdict
from string import ascii_letters
d= collections.defaultdict(int)
for letter in post:
d[letter] += 1
print [letter for letter in sorted(d, key=d.get, reverse=True) if letter in ascii_letters][2]
Any comments on improvement for readability or conciseness?
- follower 16y agoAh, your use of the collections module prompted me to read the docs for it (who would've guessed :) ) which leads to a revision of my other response: import string, collections s = "your text here" print collections.Counter([i for i in s.lower() if i in string.letters]).most_common(3)[-1]