← Back to challenges

Widen the Streets!

PythonHardarraysstringsformatting

Instructions

Given a list of strings depicting a row of buildings, create a function which sets the gap between buildings as a given amount.

Examples

widen_streets([
  "###   ## #",
  "### # ## #",
  "### # ## #",
  "### # ## #",
  "### # ## #"
], 3) ➞
[
  "###       ##   #",
  "###   #   ##   #",
  "###   #   ##   #",
  "###   #   ##   #",
  "###   #   ##   #"
]

widen_streets([
  "## ### ###",
  "## ### ###",
  "## ### ###",
  "## ### ###"
], 2) ➞
[
  "##  ###  ###",
  "##  ###  ###",
  "##  ###  ###",
  "##  ###  ###"
]

widen_streets([
  "# # # # #"
], 2) ➞
[
  "#  #  #  #  #"
]

Notes

  • Buildings may be different sizes.
  • There will always be a starting gap size of one character.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.