Code Logo

Broadcast Rundown Line Numbering

Published at22 Apr 2026
Python String Handling Medium 0 views
Like0

A producer copied the next show's rundown out of a planning document, but the pasted block still contains blank lines and internal notes. Real on-air items should appear in the final rundown. Comment lines should not.

The rules are simple but they stack together. Split the block into lines, trim outside whitespace from each line, ignore any line that becomes empty, and also ignore any trimmed line that starts with #. The remaining lines should be numbered in order as strings like "1. Opening tease", "2. Weather desk", and so on.

For example, if the input contains " Opening tease\n# hold this for later\n\nWeather desk ", the result should be ["1. Opening tease", "2. Weather desk"]. The comment line disappears entirely, the blank line disappears too, and the kept lines are renumbered from the top.

This is a text-cleanup job where filtering and formatting happen in the same pass. The output is not another block of pasted text. It is a clean ordered list of the lines that are actually meant to reach air.

Example Input & Output

Example 1
Input
script = "# prep notes\n# another note"
Output
[]
Explanation

A block made entirely of comments produces no rundown items.

Example 2
Input
script = "Desk hit\nRemote guest\nClosing credits"
Output
["1. Desk hit", "2. Remote guest", "3. Closing credits"]
Explanation

A clean rundown still needs numbering, even when nothing is filtered out.

Example 3
Input
script = " Opening tease\n# hold this for later\n\nWeather desk "
Output
["1. Opening tease", "2. Weather desk"]
Explanation

Comment and blank lines disappear, and the kept lines are renumbered cleanly.

Algorithm Flow

Recommendation Algorithm Flow for Broadcast Rundown Line Numbering
Recommendation Algorithm Flow for Broadcast Rundown Line Numbering

Solution Approach

This problem is easiest to solve if you think in stages: first break the pasted block into individual lines, then decide which lines are real rundown items, and only after that apply the numbering.

That order matters because the numbers depend on how many valid lines survive the filtering step. If you number too early, blank lines and comment lines will throw off the count.

A good Python approach starts with splitlines(), since the input is fundamentally a multiline text block. Then you loop through each line, call strip(), and check two conditions. If the trimmed line is empty, skip it. If it starts with #, skip it as well. Everything else becomes a real broadcast item and should receive the next number.

A direct implementation looks like this:

items = []
for line in script.splitlines():
    cleaned = line.strip()
    if not cleaned or cleaned.startswith("#"):
        continue
    items.append(f"{len(items) + 1}. {cleaned}")
return items

The loop does two useful things at once. It filters the input and builds the numbered output incrementally. Because the numbering is based on the current size of items, only accepted lines affect the final numbering sequence.

You could also separate the work into two passes: first build a list of valid lines, then use enumerate() to attach the numbers afterward. That version is also perfectly sound. In both cases, the core idea is the same: comments and blanks do not count as rundown entries, so numbering must happen only after those lines are excluded.

This makes the challenge slightly more involved than plain splitting because each line needs a decision before it can become part of the result. That is what makes it a better medium-level cleanup task: the final answer depends on a combination of line handling, conditional filtering, and ordered formatting.

Best Answers

python - Approach 1
def build_broadcast_rundown(script):
    valid = []
    for line in script.splitlines():
        cleaned = line.strip()
        if cleaned and not cleaned.startswith("#"):
            valid.append(cleaned)
    return [f"{i + 1}. {line}" for i, line in enumerate(valid)]