Difference between List,Tuple,Set and Dictionary in Python

Difference between List,Tuple,Set and Dictionary in Python

The below are the differences between List,Tuple,Set and Dictionary in Python,

S.No.ListTupleSetDictionary
1List stores group of elements.Tuple stores group of elements.Set stores group of elements.Dictionary stores group of elements as key-value pairs.
2Insertion Order is preserved.Insertion Order is preserved.Insertion Order is not preserved.Insertion Order is not preserved.
3Lists stores duplicates.Tuples stores duplicates.Duplicates are not allowed.Duplicate Keys are not allowed but duplicate values are allowed.
4Lists are mutable.Tuples are immutable.Sets are mutable.Dictionaries are mutable.
5List supports +ve and -ve indexes.Tuples supports +ve nd -ve indexes.Indexes are not supported in Set.Indexes are not supported in Dictionary.
6We can create List by square brackets [ ].We can create Tuple by paranthesis ( ).We can create Set by using curly braces { }.We can create Dictionary by using curly braces { }.
7Inside List elements are separated by , comma. Inside Tuple elements are separated by , comma.Inside Set elements are separated by , comma.Inside Dictionary keys and values are separated by : colen.
8List is a class type
<class ‘list’>
Tuple is a class type
<class ‘Tuple’>
Set is a class type
<class ‘set’>
Dictionary is a class type
<class ‘dict’>
9We can create list by using predefined function list().We can create Tuple by using predefined function tuple().We can create Set by using predefined function set().We can create Dictionary by using predefined function dict().
10We can access List elements by using
a)Index [ ]
b)Slice Opeartor [::]
c)Loops (for & while)
We can access Tuple elements by using
a) Index [ ]
b)Slice Operator [::]
Indexing and Slicing are not supported.Indexing and Slicing are not supported.
11We can update List elements by using [ ] index.We cannot update Tuple elements as they are immutable.We can update only Sictionary values by using [ ] index.
12List index starts from 0.Indexing is not supported.
13List supports membership operators,
a)in
b)not in
Set supports membership operators,
a)in
b)not in
14List Comprehension is supported.Tuple comprehension is not supported.Set Comprehension is supported.Dictionary Comprehension is supported.
15Methods & Functions of List
a)len()
b)count()
c)append()
d)insert()
e)extend()
f)remove()
g)pop()
h)reverse()
i)sort()
j)copy()
k)+
l)*
m)<,<=,>,>=,==
n)
o)
Methods & Functions of Tuple
a)len()
b)count()
c)index()
d)min()
e)max()
f)
g)sorted()
h)
i)
j)
k)+
l)*
m)
n)
o)
Methods & Functions of Set
a)
b)add()
c)update()
d)
e)
f)remove()
g)pop()
h)
i)
j)copy()
k)union()
l)intersection()
m)diffrence()
n)discard()
o)clear()
Methods & Functions of Dictionary
a)len()
b)get()
c)keys()
d)values()
e)items()
f)
g)pop()
h)popitem()
i)
j)copy()
k)
l)
m)
n)del keyword
o)clear()

Leave a Reply