wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Day 4: Dictionary Fundamentals

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Given model_config = {"learning_rate": 0.001, "epochs": 100, "batch_size": 32}, which statement best explains why accessing model_config["epochs"] is considered O(1)?

a)

Because the dictionary sorts keys to speed up searching

b)

Because lists store keys sequentially for fast access

c)

Because Python caches values to avoid computation

d)

Because hash tables enable constant-time key lookup

2.

You need to read a configuration value that might be missing. Which code safely returns a default of 0.001 for learning_rate?

a)

lr = model_config.get("learning_rate"); 0.001

b)

lr = model_config.get["learning_rate"] == 0.001

c)

lr = model_config["learning_rate"] or 0.001

d)

lr = model_config.get("learning_rate", 0.001)

3.

Which method both removes a key and returns its value from a Python dictionary?

a)

del dict[key]

b)

dict.pop(key)

c)

dict.update({key: value})

d)

dict.clear()

4.

Given config = {'epochs': 50, 'lr': 0.01}, which single operation will add momentum: 0.9 without altering existing keys?

a)

config.clear()

b)

del config['momentum']

c)

config.pop('momentum', 0.9)

d)

config.update({'momentum': 0.9})

5.

You have labels = ['cat','dog','fox']. Which comprehension correctly builds {'cat':0,'dog':1,'fox':2}?

a)

{label: i for i, label in zip(range(len(labels)), labels)}

b)

{idx: label for idx, label in enumerate(labels)}

c)

{label: idx for idx, label in enumerate(labels)}

d)

{k: v for k, v in labels}

6.

In the diagram, model_results['experiment_1']['metrics']['accuracy'] uses direct indexing. Which approach safely reads the same nested value if any intermediate key might be missing?

a)

model_results.setdefault('experiment_1',{}).update({'accuracy':0})

b)

model_results.get('experiment_1',{}).get('metrics',{}).get('accuracy',0)

c)

model_results['experiment_1']['metrics'].pop('accuracy',0)

d)

model_results.keys()['experiment_1']['metrics'].get('accuracy',0)

7.

You have default = {'lr': 0.001, 'epochs': 100} and user = {'lr': 0.01, 'momentum': 0.9}. Which statement produces a merged config where user overrides default?

a)

final = default.update(user) returning merged dict

b)

final = {**user, **default} with 'lr' from default

c)

final = {**default, **user} with 'lr' from user

d)

final = default | user with 'lr' unchanged

8.

In the code snippet shown, response.json() returns which Python data type when the remote payload is a JSON object with nested arrays and numbers? (Refer to the request block image.)

a)

A bytes object with encoded JSON

b)

A string containing raw JSON text

c)

A dict with lists and ints/floats

d)

A flat tuple of key–value pairs

9.

Which mapping correctly pairs a JSON structure with its Python equivalent for AI API parsing?

a)

JSON number maps to Python int/float

b)

JSON array maps to Python dict

c)

JSON string maps to Python bytes

d)

JSON object maps to Python list

10.

Which file mode should you use to add a new log entry to the end of an existing file without overwriting its current contents?

a)

"r" to read existing lines safely

b)

"a" to append new content at end

c)

"r+" to read only from the file

d)

"w" to write a fresh empty file

11.

A data pipeline processes a very large text file. Which approach best minimizes memory usage while still reading all records?

a)

Copy file to another location first

b)

Iterate for line in f within a with block

c)

Use f.readlines() to store full list in RAM

d)

Use f.read() to load entire file string

12.

You need to save a Python dict of model metrics to config.json in a human-readable way. Which statement correctly writes the JSON file?

a)

json.loads(metrics, indent=4) after opening file

b)

json.dumps(metrics) and ignore file handle

c)

open("config.json", "r") then json.load(f)

d)

json.dump(metrics, f, indent=4) inside with open("config.json", "w")

13.

In a Python training script that loads hyperparameters from a JSON file, which step best ensures experiment reproducibility across runs?

a)

Increase epochs until accuracy improves

b)

Store results using json.dump with indent

c)

Load config.json with json.load at start

d)

Print the model name to the console

14.

Look at the command line snippet shown: git add . → git commit -m "Add training script" → git push origin main. What is the primary purpose of the git add . step in this workflow?

a)

Push local commits to the remote origin

b)

Merge the main branch into a feature branch

c)

Create a new remote repository on GitHub

d)

Stage all current changes in the repository

15.

You have created a repository named ai-course-week1 and want to upload Day 1–4 notebooks. Which ordered sequence of commands correctly completes the task after editing files locally?

a)

git add . → git push origin main → git commit -m "Add notebooks"

b)

git push origin main → git commit -m "Add notebooks" → git add .

c)

git add . → git commit -m "Add notebooks" → git push origin main

d)

git commit -m "Add notebooks" → git add . → git push origin main