Day 1 – Python Syntax and Data Structures
Today's Focus
Get fluent with Python syntax, control flow, and the built-in data structures you will use every day.
Tasks
- Write a Python script that reads a plain text file of names (one per line) and produces a summary: total count, alphabetically sorted list, names longer than 8 characters, and the most common first letter. Use only built-in functions — no imports yet.
- Implement a function that takes a list of integers and returns a dictionary with keys
"min","max","mean", and"median"computed without using thestatisticsmodule. Handle the edge case of an empty list by raising aValueErrorwith a clear message. - Practice list comprehensions and generator expressions: rewrite three
for-loop solutions as comprehensions. Measure the difference withtimeitand note which is faster. - Build a nested data structure representing a small library catalogue (a list of dicts, each with
title,author,year, andtagsas a list). Write functions to filter by tag, sort by year, and search by partial title match. - Use
try/except/else/finallyto wrap a file-open operation. CatchFileNotFoundErrorseparately from a generalException. Print a different message for each case and always close the file infinally(or use awithstatement and explain why it is equivalent).
Reading / Reference
- Python Official Tutorial — Chapters 3–5: numbers, strings, lists, flow control, and data structures.
- Real Python: Python Data Structures — a practical tour of lists, dicts, sets, and tuples.
- Python docs:
timeit— Measure execution time.