Search anything:

List vs Tuple vs Dictionary in Python

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

In this article, we have explored the differences between List, Tuple and Dictionary in Python.

what is list,tuple,dictionary?
Accessing the elements
Adding an element
Removing an element
some methods



Hola everyone! Most of us know to do code using list, tuple and dictionaries in python separately without any confusions, but when we came to work with all the three together we would get confused, so to avoid those confusions this article helps you in a clear understanding of list, tuple,dictionary. Lets get started!!!

What is list,tuple,dictionary?

lists ,tuple, dictionaries are the built in data types in python used to store the collections of data. Ahh whats new in that? arrays can do this well right? why do we need list,tuple and dictionary then?
arrays can store only the homogenous data type whereas list ,tuple, dictionaries can store multiple data types in a single variable.we will see this visually futher in this article.


Hey peeps,now we know what is list,tuple and dictionary. then what's next? yeah, you guessed it correct!! we are going to create them now.

Lists are created using [ ] square brackets,a list can different data types.

list4=["apple", 1, 98,True]

Now you can able to see the advantage of using list instead of array which i have mentioned in introduction.

Tuples are created as same as the list ,but we use ( ) instead of square brackets.


Dictionaries are created by placing the sequence of elements inside the curly braces {}, in addition it contains the pair of values, key:Value.
values can be duplicated and can be of any data type but the keys cannot be repeated.

dict = {
"Name" : "Anusha"
"Reg No" : 51
"School" : "VCHSS"


Accessing the elements

okay we created the lists, tuple and dictionary ,now how to access the elements in them? can we access the elements with the same method for all three ? lets see.

In List and Tuple we can access the elements by using index,whereas in dictionary we can access the elements by reffering key values. may be it would be vague without seeing an example,let we jump into an example.




You would have got a clearance about how to access elements in list vs tuple vs dictionary.


An object is mutable if the value of the object can be changed else it is immutable

Lets see whether list,tuple dictionary are mutable or immutable
List and dictionaries are mutable whereas Tuples are immutable



if we try to change element in tuple it will give an error:(

Adding an element

we can add a element in list by using append(),insert()


Unlike list we cannot add a element in dictionary using append(),insert() we can add a element in the dictionary by defining a value along with key eg: dict1[key]='value'

>>dict1={"Chocolate":"Dairy Milk","Brand":"cadbourys"}
{'Chocolate':'Dairy Milk','Brand':'cadbourys','Rupees':100}

Unlike list and dictionary we cannot add a element in tuple as it is immutable.

Removing an element

We learned how to add elements in list vs dictionary vs tuple , now lets see how to remove an element.

We can remove an element from list by del() (removes element at the specified index,but not returns the value),remove() (removes by element value),pop()(removes the element at the specified index and returns the value).

>>del list1[2]

Like as list, we can remove elements in dictionary by using del(),pop() method but removes by the specified key name:

>>del dict1["Height"]
>>dict2={"Vehicle":"Bike","Model":"Bullet 350","price":260000}

Unlike list and dictionary we cannot directly remove an element using index value.

Some methods

Sort() / sorted()

We can use sort() method in list to sort the elements in the list.
In dictionary we can use this sorted() method to sort the keys in the dictionary by default.

The elements in the tuple cannot be sorted as it is immutable



The count() method returns the number of times the specified element occurs in list and tuple.

In dictionary the count() method is not defined.



And finally we have learned creating, manipulating, removing and some functions in list vs tuple vs dictionary. I think we have covered the major difference in list vs tuple vs dictionary. and I hope you would have got a clarification on using tuple vs dictionary vs list.Then what are you waiting for? just go and practice what you learned:)

keep coding!!!

List vs Tuple vs Dictionary in Python
Share this