List vs Dictionary in Python — Python Technical Interview Questions & Answers
List vs Dictionary in Python
List vs Dictionary in Python
- List is position-based. names[0] is the first student. Dict is key-based. marks["Asha"] is 90. Use a list when order matters and you walk items in a row. Use a dict when you look up by a label — name, roll, email — not by seat number.
- You can store dicts inside a list (rows of students) or lists inside a dict (hobbies per name). Index vs key is the clean comparison line. Pick dict when “find Asha’s marks” should not scan the whole list.
- List vs Dictionary in Python — output: Asha then 90. List by position, dict by name.
{ "Asha": 90, "Ravi": 85 }
│ │
key valueTechnical Interview Tip: When would you pick dict over list?
Code Examples for List vs Dictionary in Python
Example
# List vs dict
names = ["Asha", "Ravi"]
marks = {"Asha": 90, "Ravi": 85}
print(names[0])
print(marks["Asha"])
List vs Dictionary in Python — output: Asha then 90. List by position, dict by name.
How to Explain List vs Dictionary in Python to an Interviewer
Explain List vs Dictionary as if you are teaching a junior — definition, then one tiny script.
List: index Dict: key
What does the example print, and why?
List vs Dictionary in Python — output: Asha then 90
What mistake do freshers make with List vs Dictionary?
Sequence vs map