Read the tail of a log
Before you start this beginner track
Variables, strings, and basic lists. Build up to dictionary counting.
Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.
Understand it, then try it.
A list preserves the order of its entries. Negative indexes count from the end, so -2 identifies the second-to-last item. A slice beginning there and ending at the list’s end keeps the latest two events. join displays those events as a readable sequence without changing the original list.
events = ["boot", "scan", "sync", "sleep"]recent = events[-2:]summary = " -> ".join(recent)print(summary)Run each standalone script with Python 3.8+. File names and log entries are in-memory sample text; no files, packages, or input are required.
Track the values line by line. Predict the result before running this example in your own editor.