Data Visualization: Show the gaps

Before drawing a daily line chart, fill in the calendar so that missing days become visible gaps instead of being bridged by the line.

What to build

A program that lists every day in a range and marks the missing ones.

Requirements

  • For every day from the earliest to the latest date, in order, print YYYY-MM-DD VALUE with the value as given, or YYYY-MM-DD gap if the day has no record.

Input

Line 1: n. Then n lines YYYY-MM-DD VALUE, in any order, with distinct dates.

Output

One line per day.

Constraints

1 ≤ n ≤ 1000; the range covers at most 1000 days.

Example

Input:

2
2024-01-30 5
2024-02-02 7

Output:

2024-01-30 5
2024-01-31 gap
2024-02-01 gap
2024-02-02 7

Why it works

A full calendar makes every missing day explicit, so a chart can break its line there instead of inventing values by joining the neighbours.

Examples

Example 1 · Input
2
2024-01-30 5
2024-02-02 7
Expected output
2024-01-30 5
2024-01-31 gap
2024-02-01 gap
2024-02-02 7
Example 2 · Input
3
2024-02-28 1
2024-02-29 2
2024-03-01 3
Expected output
2024-02-28 1
2024-02-29 2
2024-03-01 3

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

date.fromisoformat parses each date; timedelta(days=1) steps through the calendar.

Hint 2

Walk from the earliest to the latest date and look each day up in a dictionary.

Solution

Show one correct solution (try it yourself first)
from datetime import date, timedelta

n = int(input())
values = {}
for _ in range(n):
    d, v = input().split()
    values[date.fromisoformat(d)] = v
day, last = min(values), max(values)
while day <= last:
    print(day.isoformat(), values.get(day, "gap"))
    day += timedelta(days=1)

Lesson: Visualizing time series →