names = ['Agrajag', 'Colin', 'Deep Thought', 'Ford Prefect',
    'Zaphod Beeblebrox', 'Zarquon']
num_pages = 3

def group_names(names, num_pages):
    letter_groups = defaultdict(list)
for name in names:
    letter_groups[name[0].upper()].append(name)
letter_groups = [letter_groups[key] for key in sorted(letter_groups.keys())]
current_group = []
page_groups = []
group_size = len(names) / num_pages
for group in letter_groups:
    current_group.extend(group)
if len(current_group) > group_size:
    page_groups.append(current_group)
current_group = []
if current_group:
    page_groups.append(current_group)
return page_groups
print(group_names(names, num_pages))
Python: разбить список имен на подсписки одинакового размера