Problem 188517 · easy · Phase 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

  • 0 <= len(data) <= 100
  • 1 <= count <= 50; labels are non-empty and 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…