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
PostgreSQLv16

Koodin suorituksen tulos näkyy tässä

Tests12
Visible tests
Piilotettu testi 7
Piilotettu testi 8
Piilotettu testi 9
Piilotettu testi 10
Piilotettu testi 11
Piilotettu testi 12

They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.

Focus radio
Paused · SomaFM · Fluid