Напишите функцию, которая будет принимать строку и возвращать список подстрок из символов этой строки, собранных и разобранных посимвольно.
Пример
construct_deconstruct("the sun") ➞ [
"t",
"th",
"the",
"the ",
"the s",
"the su",
"the sun",
"the su",
"the s",
"the ",
"the",
"th",
"t"
]
# Обратите внимание на пробел
Варианты решения
def construct_deconstruct(s):
half = [s[:i] for i in range(1, len(s) + 1)]
return half + half[:-1][::-1]
def construct_deconstruct(s):
return [s[:-abs(i)] or s for i in range(-len(s)+1,len(s))]