[go: up one dir, main page]

0% found this document useful (0 votes)
3 views2 pages

Comparison

The document outlines the key differences between List, Tuple, Set, and Dictionary in Python, focusing on their mutability, order, uniqueness, and data structure. Lists and Tuples are ordered collections that allow duplicates, while Sets are unordered collections of unique elements and Dictionaries are collections of key-value pairs with unique keys. Additionally, it provides syntax, creation methods, and various operations applicable to each data type.

Uploaded by

tkulkarni2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Comparison

The document outlines the key differences between List, Tuple, Set, and Dictionary in Python, focusing on their mutability, order, uniqueness, and data structure. Lists and Tuples are ordered collections that allow duplicates, while Sets are unordered collections of unique elements and Dictionaries are collections of key-value pairs with unique keys. Additionally, it provides syntax, creation methods, and various operations applicable to each data type.

Uploaded by

tkulkarni2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Parameters List Tuple Set Dictionary

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.

Key Difference Between List, Tuple, Set, and Dictionary in


Python
Mutability:

 List: Mutable (modifiable).


 Tuple: Immutable (non-modifiable).
 Set: Mutable, but elements inside must be immutable.
 Dictionary: Mutable; keys are immutable, but values can change.

Order:

 List: Maintains order of elements.


 Tuple: Maintains order of elements.
 Set: No guaranteed order.
 Dictionary: As of Python 3.7+, insertion order is preserved.

Uniqueness:

 List: Allows duplicates.


 Tuple: Allows duplicates.
 Set: Only unique elements.
 Dictionary: Unique keys, values can be duplicated.

Data Structure:

 List: Ordered collection.


 Tuple: Ordered collection.
 Set: Unordered collection.
 Dictionary: Collection of key-value pairs.

You might also like