Python Complex Data Structure

  • By Sneha Ranbhidkar
  • February 20, 2023
  • Python
Python Complex Data Structure

Python Complex Data Structure

Basically we know the structure of data . but how to manage . ? how to deal with that . ?

Don’t know . . . . . . .

For that purpose in our programming language the subject was introduced named as 

DATA STRUCTURE . .

Basically this Is a platform where you can arrange data in well manner

What Is next . ?

Apply the algorithms on that data and perform operations . . .

So basically the terms are like . . . 

ARRAY

STACK 

QUEUE

And many more . . . . .

 

For Free, Demo classes Call: 02071171500

Registration Link: Click Here!

 

All these terminology was born from DATA STRUCTURE . . . . .

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

SO LETS START TO IMPLEMENT THE DATA STRUCTURE CONCEPT IN OUR PYTHON

COLLECTIONS

This is the package where you can arrange data in two ways . . . 

Ordereddict

Defaultdict

Lets start with ordereddict – – – – 

Are you looking to advance your skills in Python programming? Look no further than Python Classes in Pune! SevenMentor provides a comprehensive introduction to Python’s object-oriented programming, with a particular emphasis on Python.

 

Collections.ordereddict : – >

It remembers the order of keys which are provided while storing the data in dictionary format.

Example :

# firstly import package collections

Import collections

# then create a variable which stores the data in dictionary platform

Xyz = collections . ordereddict ( five = 5 , six = 6, seven = 7, eight = 8 , nine = 9 )

# then call the variable

Xyz

The output will come like = 

. ordereddict ( [ ( ‘ five = 5 ‘ ) , ( ‘ six = 6 ‘ ) , (  ‘ seven = 7 ‘ ) , ( ‘ eighteen = 18 ‘ )  , ( ‘ ninteeen =1 9 ‘ ) ] )

 

 

For Free, Demo classes Call: 02071171500

Registration Link: Click Here!

 

So in this platform just because of dictionary it’s a mutable platform so we can modify the data how lets see

Xyz [ ‘ twentyyyth ‘ ] = 20

Then again call the variable

Xyz

You will get updated result 

. ordereddict ( [ ( ‘ five = 5 ‘ ) , ( ‘ six = 6 ‘ ) , (  ‘ seven = 7 ‘ ) , ( ‘ eighteen = 18 ‘ )  , ( ‘ ninteen =1 9 ‘ ) , ( ‘ twenty = 20 ‘ ) ] )

If you want to see only keys you can check it with help of keys () method

Xyz . keys ( )

Odict ( [ ‘ five ’ , ‘ six ‘ , ‘ seven ‘ , ‘ eighteeen ‘ , ‘ ninteen ‘ , ‘ twentyy ’ ] )

To get the values implement values () method

Xyz . values ( )

Odict ( [ ‘ 5 ’ , ‘ 6 ’ , ‘ 7 ‘ , ‘ 8 ‘ , ‘ 9 ‘ , ‘ 10 ‘] )

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  = = = = = = = = = = = = = = = = = = = = = 

Lets move to defaultdict

Collections.defaultdict : – >

Already we have ordereddict platform but this platform did not provide the missing keys so to overcome this drawback 

Defaultdict was created . . . . lets see how it performs :

 

For Free, Demo classes Call: 02071171500

Registration Link: Click Here!

 

Example :  : 

From collections import defaultdict

Sss = defaultdict ( list )

Sss [ ‘ cat ‘ ] . append ( ‘ pussy ‘ )

Sss [ ‘ cat ‘ ] . append ( ‘ lazy ‘ )

Sss [ ‘ cat ‘ ] . append ( ‘ mussy ‘ )

Sss [ ‘ cat ‘ ] . append ( ‘ cutey ‘ )

Sss [ ‘ cat ‘ ] . append ( ‘ angry ‘ )

 

Sss [ ‘ cat ‘ ]

Output

[ ‘ pussy ‘ , ‘ lazy ‘ , ‘ mussy ‘ , ‘ cutey ‘ , ‘ angry ‘ ]

 

Author:-

Sneha Ranbhidkar
Call the Trainer and Book your free demo Class For Python

Call now!!! | SevenMentor Pvt Ltd.

© Copyright 2021 | Sevenmentor Pvt Ltd.

Submit Comment

Your email address will not be published. Required fields are marked *

*
*