✏️ Explanatory Question

What is the difference between a dictionary and a list?

👁 222 Views
📘 Detailed Answer
222
Total Views
7
Related Qs
0%
Progress
💡

Answer with Explanation

Attribute Dictionary List
Data Structure Key-Value Pairs Ordered Collection
Mutability Mutable Mutable
Indexing Key-based Integer-based
Type of Values Heterogeneous Homogeneous or Heterogeneous
Order Unordered Ordered
Keys Unique, Immutable No restrictions

A dictionary is a collection of key-value pairs, where each key is unique and used to retrieve the corresponding value. Lists are ordered collections of items, which can be of any data type, including other lists. The items in a list are indexed by integers, whereas the elements in a dictionary are referenced by their keys.