我在做这个练习:
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]
将从第一个元素中获取第一个字符
但是,我需要它递归地使用字典、循环(for
或while
或其他)、zip
或导入任何模块。从每个字符串中取第一个字母,然后查看它是否遵循上述规则
目前没有回答
相关问题 更多 >
编程相关推荐