Start learning free

LESSON 609 OF 673 · PROJECTS: COMMAND-LINE TOOLS

CLI Tool: wc v1 — Count Lines

Practice

Build a tiny version of the Unix wc command. Given a list of lines, return the total number of lines as an integer.

Function signature:

def countLines(self, lines: List[str]) -> int:

Example:

Input: lines = ["hello", "world", "foo", "bar", "baz"]

Output: 5

Every entry of the list is one line, even an empty string "". An empty list has 0 lines.


The number of lines is just the length of the input list. Python has a built-in for that — no loop needed.

A one-liner using len:
class Solution:
    def countLines(self, lines):
        return len(lines)

STEP 1 OF 1
    Ctrl + Enter to check