Data Structure

What is data structures?
They are structures which can hold some data together. Its a way of organizing and storing data so that they can be accessed and worked easily.
There are 4 built in data structures in python – list, tuple, dictionary and set.

Definitions:

List: is a collection which is ordered and changeable.
Tuple: is a collection which is ordered and unchangeable.
Dictionary: is an unordered collection of data values.It easier to read and change data
Set: A Set is an unordered collection data type that is iterable, mutable, and has no duplicate elements.

Lists:

Lists in Python are used to store collection of heterogeneous items. The contents can be changed during the execution of the program. It is written between square brackets separated by comas. The items in a list need not be of the same type.

Updating Lists:

You can update the existing list either by using slice or by using append().

Deleting list elements:

You can use either the del statement or remove().

Basic List Operations:

Tuple:

Its similar to list but its contents once initialized it can be accessed but cannot be changed throughout the program. Its enclosed within two parenthesis() and are separated by comas.

Updating tuples:

We cannot change the contents of the tuples but we can perform operations and store it in another tuple

Delete tuples:

Removing individual tuple isn’t possible cause its not changeable. We can delete the entire tuple. Using the keyword del.

Basic operations in tuples:

Dictionary:

A dictionary in python makes it easier to read and change data, thereby rendering it more actionable for predictive modeling. A Python dictionary is an unordered collection of data values. Python dictionary holds a key. The Python dictionary allows it to access values when the key is known. You can use only immutable objects (like strings) for the keys of a dictionary but you can use either immutable or mutable objects for the values of the dictionary.

Updating dictionary:
Dictionary’s contents as well as the length can be modified in the program

Delete dictionary:
We can delete the dictionary contents as well as the whole dictionary.

Set

A Set is an unordered collection data type iterable, mutable, and has no duplicate elements. Advantage of using a set is that it has a highly optimized method for checking whether a specific element is contained in the set.

Frozensets are like sets except that they cannot be changed we can use frozenset for dictionary and normal set.

Author:Nivedita.M.
Edited by:Arcot Gautham.

Leave a comment