Chain of Consequences
Sometimes one small missing thing starts a whole chain of consequences: no nail, then no shoe, then no horse, and so on. The function proverb receives a list of words items and builds proverb lines for each adjacent pair. Add the final line about the first item in the list, and return an empty list if items is empty.
Примеры
Ввод
[]Вывод
[]Ввод
["nail"]Вывод
["And all for the want of a nail."]Ввод
["nail", "shoe"]Вывод
["For want of a nail the shoe was lost.", "And all for the want of a nail."]Нужно реализовать
def proverb(items: list[str]) -> list[str]:
Теги
listsstrings
Log ind for at se indsendelseshistorik
Log indLog ind for at bruge AI-mentor
Log indVisible tests
1
Input
[]Expected
[]2
Input
["nail"]Expected
["And all for the want of a nail."]3
Input
["nail","shoe"]Expected
["For want of a nail the shoe was lost.","And all for the want of a nail."]4
Input
["nail","shoe","horse"]Expected
["For want of a nail the shoe was lost.","For want of a shoe the horse was lost.","And all for the want of a nail."]5
Input
[0]Expected
["And all for the want of a 0."]6
Input
[1]Expected
["And all for the want of a 1."]Focus radio
Paused · SomaFM · Fluid