Index an image folder
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 dictionary associates each key with a value. This loop uses file extensions as keys and records how often each appears. get supplies zero when an extension has not been seen before. Adding one then updates that extension’s count, including repeated extensions, without requiring a separate initialization branch.
extensions = ["jpg", "svg", "jpg", "png", "jpg"]counts = {}for extension in extensions: counts[extension] = counts.get(extension, 0) + 1print(f"jpg:{counts['jpg']}, png:{counts['png']}")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.