← Back to challenges

Construct and Deconstruct

PythonHardlanguage_fundamentalsstringsarraysloops

Instructions

Given a string, create a function that outputs a list, building and deconstructing the string letter by letter. See the examples below for some helpful guidance.

Examples

construct_deconstruct("Hello") ➞ [
  "H",
  "He",
  "Hel",
  "Hell",
  "Hello",
  "Hell",
  "Hel",
  "He",
  "H"
]

construct_deconstruct("innokodakademija") ➞ [
  "e",
  "ed",
  "eda",
  "edab",
  "edabi",
  "innokodakademija",
  "edabi",
  "edab",
  "eda",
  "ed",
  "e"
]

construct_deconstruct("the sun") ➞ [
  "t",
  "th",
  "the",
  "the ",
  "the s",
  "the su",
  "the sun",
  "the su",
  "the s",
  "the ",
  "the",
  "th",
  "t"
]

Notes

Include spaces (see example #3).

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Operations