Color theme
0 day streak0 XPP1
PythonLearn mode
MISSION 1 OF 1

Index an image folder

0 XP earned
Python track: BeginnerMission: IntermediateDictionariesFrequency countingDefault values
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.

x
0 / 2 challenges
LEARN THE CONCEPT

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.

mission.py
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.