avatar Bite 304. Most identical letters in a word

In this Bite, you will write a function called max_letter_word() to identify the first word with the most repeated letter in the supplied text, and return a tuple with the word, the letter, and the count of that letter in the word. For example:

>>> max_letter_word('The studio was filled with the rich scent of roses')
('filled', 'l', 2)

For this Bite you may like to use features like built-ins and comprehensions, and you might also find something useful in the collections module that helps (hint, it's Counter).

For a given letter your solution should not differentiate by case, thus the 'S' and 's' in 'Sister' count as the same letter: str.casefold() is perhaps the best way to achieve this since it has the added advantage of expanding some tricky characters to their constituent letters. For example:

>>> "Schloß".casefold()
schloss

Words are separated by white space; hyphenated words count as a single word, as do abbreviated words. Anything containing letters (including non-English letters) can be assumed to be a word, but don't count its non-letter symbols, digits etc. Leading or trailing non-letter symbols, digits etc (including ' and -) should be removed from the returned word.

Do review the Bite's tests for further example texts with their expected output; also to identify edge cases and see what behaviour is expected for invalid input.

Have fun with the power of Python!

Login and get coding
go back Intermediate level
Bitecoin 3X

42 out of 47 users completed this Bite.
Will you be Pythonista #43 to crack this Bite?
Resolution time: ~80 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 7.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help