Comparison
Comparison
A set is an
A list is an ordered, A tuple is an ordered, A dictionary is an
unordered
Definition mutable collection immutable collection unordered collection
collection of
of elements. of elements. of key-value pairs.
unique elements.
Syntax includes Syntax includes Syntax includes Syntax includes curly
square brackets [ , ] curved brackets ( , ) curly brackets { , brackets { , } with ‘,’
Syntax
with ‘,’ separated with ‘,’ separated } with ‘,’ separated key-value
data. data. separated data. data.
A list can be
A set dictionary
created using the Tuple can be created A dictionary can be
can be created
Creation list() function or using the tuple() created using the
using the set()
simple assignment function. dict() function.
function.
to [].
An empty set can
Empty Data An empty list can An empty tuple can An empty dictionary
be created by s =
Structure be created by l = []. be created by t = (). can be created by {}.
set().
Ordered collection in
It is an ordered It is also an ordered It is an unordered Python version 3.7,
Order
collection of data. collection of data. collection of data. unordered in Python
Version=3.6.
Keys are unique, but
Duplicate data
Duplicate Duplicate data entry All elements are two different keys
entry is allowed in
Data is allowed in a Tuple. unique in a Set. CAN have the same
a List.
value.
Has integer based Also has integer Does NOT have Has a Key based
Indexing indexing that starts based indexing that an index based indexing i.e. keys
from ‘0’. starts from ‘0’. mechanism. identify the value.
New items can be Being immutable, The add() method update() method
Addition added using the new data cannot be adds an element to updates specific key-
append() method. added to it. a set. value pair.
Pop() method Being immutable, no Elements can be pop(key) removes
Deletion allows deleting an data can be randomly deleted specified key along
element. popped/deleted. using pop(). with its value.
Immutable, so sorting Unordered, so Keys are sorted by
sort() method sorts
Sorting method is not sorting is not using the sorted()
the elements.
applicable. advised. method.
index() returns Unordered, so
index() returns index get(key) returns value
Search index of first searching is not
of first occurrence. against specified key.
occurrence. applicable.
Immutable, so reverse Unordered, so No integer-based
reverse() method
Reversing method is not reverse is not indexing, so no
reverses the list.
applicable. advised. reversal.
count() method count() method count() not count() not defined
Count
returns occurrence returns occurrence defined for sets. for dictionaries.
Parameters List Tuple Set Dictionary
count. count.
Order:
Uniqueness:
Data Structure: