Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Group Words by First Letter with a Dictionary

Organize a list of words into groups keyed by their first letter (case-insensitive), preserving original order within groups.

Python practice15 minDictionaries & SetsIntermediateLast updated March 18, 2026

Problem statement

Given a list of non-empty strings, group the words by their first letter in a case-insensitive way. The grouping key should be the lowercase version of the first character. Preserve the order of words as they appear in the input for each group's list. Return a dictionary where keys are single-character strings and values are lists of original words.

Task

Implement a function that groups non-empty words by their lowercase first character and returns a dictionary mapping each letter to the list of words that start with it, preserving input order.

Examples

Simple grouping

Input

group_by_first_letter(['apple', 'ant', 'banana'])

Output

{'a': ['apple', 'ant'], 'b': ['banana']}

Words starting with 'a' are grouped under key 'a', and 'banana' under 'b'. Order within groups matches input order.

Input format

A list of non-empty strings.

Output format

A dictionary mapping each lowercase first letter to a list of words (strings) that start with that letter.

Constraints

Words are non-empty strings. The function should be case-insensitive for grouping (use lowercase for keys). Preserve original word order in each group's list.

Samples

Sample 1

Input

['Dog', 'deer', 'Cat']

Output

{'d': ['Dog', 'deer'], 'c': ['Cat']}

Grouping is case-insensitive; 'Dog' and 'deer' group under 'd'.