带递归的头韵

2024-09-30 22:17:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做这个练习:

Alliteration is a sentence where strictly greater than 50% of the words begin with the same letter. Write a function allit(sen) that takes a string (sen) consisting of words separated by a space, and returns true if the sentence is an alliteration, and false if not.

allit("Sam salt rides") => True
allit("Jake car") => False

到目前为止我知道

L = s.lower().split()

将字符串放入小写,并将其列为一个列表。 a = L[0][0]将从第一个元素中获取第一个字符

但是,我需要它递归地使用字典、循环(forwhile或其他)、zip或导入任何模块。从每个字符串中取第一个字母,然后查看它是否遵循上述规则


Tags: andofthe字符串ifiswheresentence