Navigate
←Back to Gym
← Back to Wall

The Gear Rack - Lists, Dicts, and Loops

Route ID: R003 β€’ Wall: W01 β€’ Released: Jan 1, 2026

5.7
ready

πŸ§— Start Here

Scroll down to complete this route

The Gear Rack: Lists, Dicts, and Loops

  • RouteID: 003
  • Wall: Getting Comfortable with Python
  • Routesetter: Adrian
  • Grade: 5.7
  • Time: ~35-60 minutes
  • You'll need: A Jupyter/Colab notebook (or any place you can run Python cells)

Why this route exists

In applied AI/ML for biochemistry, you constantly work with collections of things:

  • a list of protein sequences you want to score or cluster
  • a list of metabolites detected in an LC-MS run
  • a list of genes that pop out of a CRISPRi screen
  • a dict mapping gene β†’ log2FC or protein_id β†’ embedding_vector
  • a dict mapping compound β†’ intensity or sample β†’ metadata

In Python, containers (lists + dicts) hold those collections, and for-loops let you walk through them to do real work:

  • Filter β€” keep only hits with |log2FC| > 1
  • Count β€” how many were significant?
  • Summarize β€” top 10 by intensity
  • Transform β€” build a new dict keyed by gene name

This route is your β€œgear rack”: you’ll practice packing biological data into containers, then looping through it to generate clean, trustworthy summaries.



What you'll be able to do after this route

By the end, you can:

  • Create and edit a list
  • Create and edit a dict
  • Use for loops to iterate over:
    • list items
    • list indices (with range)
    • dict keys and dict key/value pairs (with .items())
  • Build new containers from old ones (filtered lists, count dictionaries)

What this route is NOT about (on purpose)

  • while loops
  • list comprehensions (we'll do "plain loops" first)
  • pandas / DataFrames
  • performance tricks

Route rules (common "falls" to avoid)

  • Don't name variables list, dict, or range (those are built-in names).
  • Don't write for gear in gear: (don't reuse the container name as the loop variable).
  • Don't remove items from a list while you're looping over it. Make a new list instead.
  • If you get KeyError, use .get() or check if key in my_dict.

Pitch 1 β€” Lists: Packing the rack

Setup (copy this into one cell and run it)

# A list: ordered items (can contain duplicates)
gear = ["ATC", "chalk", "helmet", "quickdraw", "quickdraw", "locking carabiner"]

Exercise 1 β€” Inspect your rack (list basics)

Goal: Check what you have and add one item. Do:

  1. Print the entire gear list.
  2. Print the number of items in gear.
  3. Print the first item and the last item.
  4. Add "tape" to the list.
  5. Print gear again to confirm it changed.

Helpful hints (not required):

  • len(gear)
  • gear[0]
  • gear[-1]
  • gear.append("tape")

Success check: You see "tape" at the end, and your length increased by 1.


Exercise 2 β€” Inventory walk (your first for-loop)

Goal: Print each item in your rack on its own line. Do:

  • Write a for loop that prints each item in gear.

Success check: You see one line per item, including duplicates like "quickdraw" twice. Common fall: If you wrote for gear in gear:, rename the loop variable: for item in gear: print(item)


Exercise 3 β€” Inventory with positions (indices)

Goal: Print index -> item for your gear list. Example output (yours can differ): 0 -> ATC 1 -> chalk 2 -> helmet ...

Do ONE of the two options: Option A (recommended):

  • Use enumerate(gear).

Option B:

  • Use range(len(gear)) and index into the list.

Success check: Your output includes both the index number and the item.


Pitch 2 β€” Filtering: Sorting gear into bins

Exercise 4 β€” Build a filtered list (don't mutate!)

Goal: Make a new list called carabiners that contains only gear items with "carabiner" in the name. Do:

  1. Create an empty list: carabiners = []
  2. Loop over gear
  3. If the item contains "carabiner", append it to carabiners
  4. Print carabiners

Helpful hint:

  • "carabiner" in item

Success check: carabiners should contain "locking carabiner". Common fall: Don't do gear.remove(...) inside your loop. That's a classic foot slip.


Pitch 3 β€” Dicts: The inventory sheet

Setup (copy this into one cell and run it)

# A dict: name --> count (keys are unique)
gear_counts = {"quickdraw": 6, "locking carabiner": 3, "helmet": 1}

Mini-intro: What is a dictionary?

A dictionary (usually called a dict) is a container that stores key β†’ value pairs. Think of it like a labeled box system:

  • key = the label (usually a string like "Rv0281" or "quickdraw")
  • value = the thing you want to store (a number, string, list, etc.)

Why biochemists love dicts:

  • gene β†’ log2FC (CRISPRi/TnSeq hits)
  • protein_id β†’ sequence
  • compound β†’ intensity
  • sample_id β†’ metadata

Two rules to remember

  1. Keys are unique: If you assign the same key twice, the later value overwrites the earlier one.
  2. You look up values by key: d["helmet"] gets the value for "helmet".

Exercise 5 β€” Dict basics + avoiding KeyError

Goal: Safely look up counts of items. Do:

  1. Print the value for "helmet" from gear_counts
  2. Try to look up "ATC" (it may not exist in gear_counts)
  3. Fix the lookup so it does not crash when the key is missing

Helpful hints:

  • gear_counts["helmet"]
  • gear_counts.get("ATC", 0)

Success check: You can request counts for both present and missing items without an error.


Exercise 6 β€” Count items from a list (frequency dict)

Goal: Build a new dict counts_from_list from gear. You want output like: {"ATC": 1, "chalk": 1, "helmet": 1, "quickdraw": 2, "locking carabiner": 1}

Do:

  1. Create an empty dict: counts_from_list = {}
  2. Loop over gear
  3. For each item, add 1 to its count

Two valid patterns (pick one): Pattern A (explicit):

  • If the item is not a key yet, start at 0
  • Then increment

Pattern B (compact):

  • counts_from_list[item] = counts_from_list.get(item, 0) + 1

Success check: counts_from_list["quickdraw"] is 2.


Exercise 7 β€” Looping over dicts (clean report)

Goal: Print a clean inventory report from counts_from_list.

Example:

ATC: 1 chalk: 1 helmet: 1 quickdraw: 2 locking carabiner: 1

Do:

  • Loop over counts_from_list.items() and print key: value

Success check: Every key/value prints once.


Pitch 4 β€” Real-ish data: A list of dict "records"

Setup (copy this into one cell and run it)

# A list of dicts: each attempt is a little record
attempts = [
    {"grade": "5.9", "tries": 2, "sent": True},
    {"grade": "5.10a", "tries": 4, "sent": False},
    {"grade": "5.10b", "tries": 3, "sent": True},
]

Exercise 8 β€” Summarize attempts

Goal: Compute:

  1. Total number of tries across all attempts
  2. A list of grades you sent (sent == True)

Do:

  • Start with:
    • total_tries = 0
    • sent_grades = []
  • Loop through attempts
  • Add attempt["tries"] to total_tries
  • If attempt["sent"] is True, append attempt["grade"] to sent_grades

Success check:

  • total_tries is the sum of the tries values
  • sent_grades contains "5.9" and "5.10b" (the routes where sent is True)

Common falls:

  • If you get KeyError, print the attempt dict and check the key spelling.
  • If your totals look wrong, print inside the loop:
    • the current tries
    • the running total_tries

Anchor Challenge β€” Rack Check (no hints)

Goal: Build a dict mapping grade -> tries using attempts. Example: {"5.9": 2, "5.10a": 4, "5.10b": 3}

Then print only the routes that took 3 or more tries. Rules:

  • Use a loop (no pandas).
  • It's fine if you print in any format you like.

Success check:

  • Your dict has one entry per route
  • Your printed output includes "5.10a" and "5.10b" (in this dataset) because they have 3+ tries

Optional "Bonus Hold" (only if you're cruising)

Rewrite Exercise 4 (filtered list) using a list comprehension. Example pattern: new_list = [item for item in gear if "carabiner" in item]

No pressure β€” the route is complete without this.

Deliverables

Please submit the following two items:

1. A completed Jupyter notebook (.ipynb)

  • The notebook should run top-to-bottom without errors.
  • It should include your code and any brief comments you added while working.
  • Please follow this file naming convention β†’ lastname_firstname_RID_003_code.ipynb
    • The RID stands for "Route ID". This would be route #003.

How to download from Google Colab:

  • In Colab, click File β†’ Download β†’ Download .ipynb
  • This will save the notebook to your computer.

2. A short logbook entry (plain text, ~5-10 sentences):

  • Briefly describe:
    • what was tricky or confusing
    • what helped you get unstuck
    • one thing you learned about working with real data
  • File naming convention β†’ lastname_firstname_RID_003_logbook.txt
  • Focus on clarity and completeness.

Submission

Submit your files by uploading them to this Google form: SUBMIT LINK

Please upload both:

  • your .ipynb notebook
  • your logbook file

Make sure filenames follow the naming conventions above.

We will fine-tune our submission system as the course moves along. Thank you for your patience as a valued member of the CHEM 169/269 Climbing Gym.

πŸŽ‰ Route Complete!

Great work!