pyassistant

Group consecutive words by starting letter

Given a list of words (strings), group consecutive words that start with the same letter (case-insensitive). Return a list of groups where each group is a list of the consecutive words sharing the same first character. Single words that don't share a starting letter with neighbors should be their own group.

Example:

Input:
(['Apple', 'apricot', 'Banana', 'berry', 'Cherry', 'citrus', 'date'])
Output:
[['Apple', 'apricot'], ['Banana', 'berry'], ['Cherry', 'citrus'], ['date']]

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.