Summarize Multi-Line Input

Medium ⏱ 12 min 47% acceptance ★★★★★ 4.8
Write a function summarize_input(text) that takes a block of text text (possibly containing multiple lines separated by \n) and returns a dict with keys "lines", "words", and "characters" giving the counts of lines, words (whitespace-separated tokens across the whole text), and characters (including newlines), respectively.

Examples

Example 1
Input
summarize_input("hello world\nbye")
Output
{'lines': 2, 'words': 3, 'characters': 15}
Explanation

2 lines, 3 words total, 15 characters including the newline.

Constraints

  • text is a non-empty string.

Topics

Input & Outputaggregating text

Companies

LinkedInAdobe

Hints

Hint 1

`text.split("\n")` gives lines; `text.split()` (no args) gives words across all whitespace.

Hint 2

`len(text)` gives the character count directly.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.