python-tutorial
python-tutorial copied to clipboard
Error in functional programming, exercise 3
The description says "using lower() to ensure consistent capitalization."
But the proposed solution is missing it:
def reference_exercise3(words: List[str]) -> List[Tuple[str, int]]:
return [(k, len(list(v))) for k, v in itertools.groupby(sorted(words, key=lambda x: x[0]), key=lambda x: x[0])]
perhaps:
itertools.groupby(sorted(words, key=lambda x: x[0].lower()), key=lambda x: x[0].lower()):
Thanks, @SerAcero! 😉