python-tutorial icon indicating copy to clipboard operation
python-tutorial copied to clipboard

Error in functional programming, exercise 3

Open SerAcero opened this issue 8 months ago • 1 comments

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()):

SerAcero avatar May 08 '25 12:05 SerAcero

Thanks, @SerAcero! 😉

edoardob90 avatar May 08 '25 12:05 edoardob90