Lists & Dictionaries
Lists and dictionaries are the workhorses of Python. A list is an ordered collection of items, perfect for sequences like scores
or tasks. A dictionary maps keys to values, ideal for structured records (e.g., a user’s name, email, and age).
You’ll use these constantly, so it’s worth learning common patterns such as iteration, lookups, updates, and comprehensions.
Lists: Create, Access, Modify
Lists are written with square brackets and support indexing, slicing, and many helpful methods (e.g., append, extend, sort).
Dictionaries: Keys & Values
Dictionaries are written with curly braces. Keys are unique and usually strings or numbers. Access values with [] or
get() (which lets you specify a default).
Iterating & Comprehensions
Loops work naturally with lists and dicts. Comprehensions compress a loop + expression into a single readable line—a great way to transform data.
Best Practices
Prefer list and dict comprehensions for clear transformations. Use get() when a key may be missing. Keep dictionaries small and focused;
if your data grows complex, consider nested dicts or custom classes. When order matters for dicts, Python 3.7+ preserves insertion order by default.
Mini Challenge
Build a shopping cart as a dictionary (item → price). Add three items, then compute total cost and apply a 10% discount if total exceeds a threshold. Print the final amount and list items sorted by price.
✅ Key Takeaways
- Lists are ordered, mutable sequences; dicts map keys to values.
- Use list/dict comprehensions for concise transformations.
- Copy carefully: list() or slicing makes shallow copies; use copy/deepcopy when needed.
- For dict iteration, use items(), keys(), values().
❓ Frequently Asked Questions
🔗 References
📅 Last Updated: November 20, 2026
Vinod Kumar
Senior Full-Stack InstructorPython & JavaScript Tutor at JoinMyTutor
Vinod teaches practical Python and JavaScript—ranging from basics to advanced web apps—with a focus on clear mental models, code readability, and interview preparation. He authors both the Python and JavaScript tracks on JoinMyTutor.