Problem 188517 · easy · Level 01 Prerequisites & Setup

Horizontal Bar Chart

loops · strings · formatting

Turn survey results into a text bar chart. data is a list of [label, count] pairs. Return one string per pair, in the given order: the label padded on the right with spaces to the length of the longest label, then a single space, then count copies of #.

Examples

Input:  data = [["tea", 3], ["coffee", 5]]
Output: ["tea    ###", "coffee #####"]

Input:  data = [["a", 1]]
Output: ["a #"]

Constraints

  • Labels contain no spaces.

Goals

  • Find the longest label before building any line
  • Pad labels to a common width and draw bars with string repetition
Starting Python…