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.

« Working with JSON Logging in Python »

✅ Key Takeaways

❓ Frequently Asked Questions

Use sorted(items, key=lambda x: x.property) or list.sort(key=...).

Yes, Python 3.7+ preserves insertion order.

Use the | operator (3.9+) or {**a, **b}.

🔗 References

📅 Last Updated: November 20, 2026

Vinod Kumar avatar

Vinod Kumar

Senior Full-Stack Instructor

Python & 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.

#Python #Flask #Pandas #JavaScript #Node.js #React #ES6+ #Async/Await #DOM Manipulation
banner