List Dictionary
The dictionary is a hashed structure of the key and value
The list is a collection of index value pairs pairs.
like ArrayList in Java and Vectors in C++.
The dictionary is created by placing elements in { } as
The list is created by placing elements in [ ]
"key":"value", each key-value pair is separated by commas
separated by commas ", "
", "
The indices of the list are integers starting The keys of the dictionary can be of any immutable data
from 0. type.
The elements are accessed via indices. The elements are accessed via key.
The order of the elements entered is They are unordered in python 3.6 and below and are ordered
maintained. in python 3.7 and above.
Lists can duplicate values since each values Dictionaries cannot contain duplicate keys but can contain
have unique index. duplicate values since each value has unique key.
Average time taken to search a value in list
Average time taken to search a key in dictionary takes O[1].
takes O[n].
Average time to delete a certain value from a Average time to delete a certain key from a dictionary takes
list takes O[n]. O[1].
List Tuple
1 Lists are mutable(can be modified). Tuples are immutable(cannot be modified).
2 Iteration over lists is time-consuming. Iterations over tuple is faster
Lists are better for performing operations, such as insertion Tuples are more suitable for accessing
3
and deletion. elements efficiently.
4 Lists consume more memory. Tuples consumes less memory
5 Lists have several built-in methods. Tuples have fewer built-in methods.
6 Lists are more prone to unexpected changes and errors. Tuples, being immutable are less error prone
Feature List Tuple
Mutability ✅ Mutable (can be changed) ❌ Immutable (cannot be changed)
Syntax [] (square brackets) () (parentheses)
Methods Available Many (e.g., append, remove) Few (e.g., count, index)
Performance Slower than tuples Faster than lists (due to immutability)
Use Case Use when items might change Use when items should not change
Memory Consumption Uses more memory More memory-efficient
Hashable (for dict keys) ❌ Not hashable ✅ Hashable if all elements are hashable
List Tuple Set Dictionary
A list is a A tuple is a sequence of A set is a built-in data A Dictionary is a collection
collection of elements separated by structure in Python that of key-value pairs, where
ordered elements. commas and enclosed in represents a collection each key is unique and
parentheses. of unique elements. associated with a value.
Lists maintain the Tuples maintain the order Sets do not maintain the Dictionaries do not maintain
order of the of the elements they order of the elements the order of the elements
elements they contain they contain they contain.
contain.
Lists can be Tuples can be accessed Sets cannot be accessed Dictionaries cannot be
accessed by index by index by index accessed by index
Lists can be Tuples cannot be Sets can be modified by Dictionaries cannot be
modified by modified by adding or adding or removing modified by adding or
adding or removing elements elements removing elements
removing
elements
Lists can contain Tuples can contain Sets cannot contain Dictionaries cannot contain
duplicate duplicate elements duplicate elements duplicate elements
elements
Lists can be Tuples can be accessed Sets cannot be accessed Dictionaries cannot be
accessed by index by index by index accessed by index