Before , we try to build comprehension of Python Data Structures , lets first try to understand What is Data Structure ..

Data Structure in a Computer Science language is a Structure that can hold some Data together.
In other words, they are used to store a Collection of Related Data.

If the definition is not clear and you are still scratching your head , then lets try to understand the same using a real life analogy -

A 'Data Structure' can be thought of as a 'Human Dwelling Structure'

A 'Human Dwelling Structure' is for 'housing' related Human Beings together.

Like ,
a) Hotel is used to house people temporarily as long as they want
b) A Stand Alone House is used for housing of only a 'Family'
c) A Gated Community is for housing various Families
d) An Office Dormitory is for housing only the Employees of an Office.

As each of the 'Human Dwelling Structures' are for housing Human Beings and have unique Properties & Purpose ,
similarly Data Structures are for housing/holding data and have unique Properties & Purpose.

Now that you have got fair understanding of 'Data Structure' , lets now focus on Various Data Structures available in Python.

Data Structures in Python

There are broadly 4 types of 'Built-in' Data Structures in Python -

1) List
2) Dictionary
3) Tuple
4) Set

Now , lets explore each of the Data Structure in Python :

a) It is a Data Structure that holds an 'Ordered Sequence' of Data / Items.
b) Once we have created a List , we can add , remove or search for items in a list
c) And for the above reason , a List is a Mutable Data Type
d) List is created in Python by enclosing the list of items in Square Bracket and separating them by Commas.

Example of List in Python Code : Shopping_List = [ 'apple' , 'milk' , 'carrot' , 'tea']


limitation of the List Data Structure is , if you want to access a specific data in the list , either you to have to know the position/index
of the data item in the List or you to read sequentially until you find your Data Item.

Dictionary Data Structure overcomes this limitation by providing a feature of Storing Data in a combination of 'Key & Value' for each
Data Item.

a) Dictionary is a collection of data items where each data item is saved as combination of 'Key' & 'Value'
b) Key value for each Data Item has to be unique & Key value is immutable
c) Data Items in Dictionary are not ordered ( Order is of no significance as you can access value directly using Key )
d) Dictionary is created in Python by enclosing the list of items in Curly Bracket and separating them by Commas.

Example of Dictionary in Python Code : Student = { 'Mohanty' : 85 , 'Mathur' : 90 , 'Bhatt' : 78 , 'Larry' : 87 }


a) Tuple is similar to List except for the difference that Tuples are Immutable ( cannot be changed )
b) Data Items in Tuple are ordered
c) Tuples are used when collection of data in a Tuple is not expected to change
d) Tuple is defined in Python by separating the items by comma and enclosing the collection of data by parenthesis.

Example of Tuple in Python Code : Courses = ( 'R' , 'Python' , 'Matlab' , 'Octave' )


a) Set is an un-ordered collection of simple Python objects
b) The Data items in a Set are Unique ( duplicate elements can not be stored in a Set )
c) Set is used when Existence of a data item is more important than the order & number of occurrences.

Example of Set in Python Code : Asia = ( ['India' , 'Butan' , 'Nepal' , 'Sri Lanka'] )
@AUTHOR : Admin

Tags:Eco, Water, Air, Environment

Comments (0)

    No Comments Found
Leave a Comment