0% found this document useful (0 votes)
71 views

Data Structure in Python Language

The document discusses different data structures in Python including lists, tuples, sets, and dictionaries. It provides examples of creating each data structure type, adding and accessing elements within each one, and some common operations that can be performed.

Uploaded by

Anand Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Data Structure in Python Language

The document discusses different data structures in Python including lists, tuples, sets, and dictionaries. It provides examples of creating each data structure type, adding and accessing elements within each one, and some common operations that can be performed.

Uploaded by

Anand Anand
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

DHTA STRUCTURES IN PYTHON

By:pythan.huh

what iS data 9ucture


Omanizing,managinq amd staring
data is
enables easier accass and eFicient
impactaote as i t
madificcztiaos
Dcta 9tructreS allaulS yau to oganize
enables yoLL do
yaur dcta in Such a uay hat
eturecOllections data,telate then and perfam
operaticns cn them_accocdingly

ypes ot data Stuues io pythoni=


DataSHructueS

DGer-defined
Built-in data.
Gtructues dartr uctures

List Tupie Stadk Tee Hasbmap

Didficnar Set ueue Graph


Pq-TyPes of dataStFueteras

yhoh has implicit suppart Be dato.


structures uhich ehabeS yauto sBore g acess data

PRU thor. hub


LiStS pythan.hub
istG are used to stoe duta.of ditferent
data types in a sequential manner.andtbere
aeacldress.es aSsigned to very element,calledindex
Creatinq a lis
Tocreate a ist+you suse square brackeER
an add element into iE acendlingly
my-listE:l #create empty ist
pdnt Cmy-ist)
my-listell2,3, 'example,3.13a#dataa
print-my-ist)
Outpu . puthan.hub
LL2,3,Xmple', 3.13a J-
Deleting element fam isti
TO dejete elemehts,use the del
Keyuor ahich daes na eum anytinq laaes

my-isteL2,3,erampleA.132,10,30J
del mu-list ld# delete elemestat nder 5_
pn Cyis-
A myispop CEpp element fhm list
pånCoppecd Eiemeria
my list.clear) Ëenpty tho ist
prn (my list-
pythanhuh
output Li2,3,erample, 3132,30a
Li2,3, 3.132, 3a
PappedElemert2

Acce ssinq Elemerte i=


Accesingelement,gau shauld pass tHe2
indec values aad hence can obtan ctlue.

my- listell23,example' 3132, 1a,3a


fore element im my-list:Ëaccess me byone
prinLelement-
printmy-1is #access all eemens
pin(my-lis[aJ) #access indec s elemeot
pint+ (ny-list [o:2#accessframato 1,eKclude2
pontmy lis L )#aceess elem.ents n resersd
Output
3

erumple
3132

30
2,3, ecamplea.182,1a,30
examplee

fao,10, 3132, erample3, -


Tuple apythan:bub_
Tupiesare Same as ist ate uith ane
excaptim that the datamco enkered int
ne tupLe _abno+ be changed no md Her adhat

Creatmq a uple -
yau an crecte a uple usinq puuenthe
-6is oc using the tupel)-function
Emy-tuple CL2,3)
prio(my-upie -

olp Cl,2,3)

Bresinq elements
Accessinq elem ets is the same aS
is for accessing values io listS

my-tuple2sCl,2,3, pytbon)Eauessng ekments


for x im my-ype 2-
pot (*-
prin-Cmy-tuple2
pntCmy-tuple ap
prn=my-uplea
prin mytuple2 [a]ryJ

alp
2

Tuolo LAPIItho
Python- @python.hub
La,3pyahan

L4,3,Rython

app.onding lemets
TDappend +Hewdlues,-yauuse +
perator ulhich will takQ aotber lple:to bee
appended to itt.

my-tuple sC,2,)
my-tuple = ns-tuple+(446 )Facdo element
prin-my-tupiejH
autpu
CI,2,3,44T
@python bub
sets are she allecian d unetlered eiemehts
that are unique It He sdata is epeatod
mre thah one ime, t cuduld be endered.
into tne set aml Once

Creatinq q teti
sets ae created usinq unsbacess-
but înstead okaclding ey ualue psicsucujust
pasS values to it

my-set-+L4,3,4,,3,2,5Creae setE
prin(my set

AddngelementS =
Toaddelements,you use theacdd
unctton and_eass tne vulu io it

my-set 2142,31-
my-setadd add element ta set
prîn= (my-set-

alp L4,3,4-
Operations in setsi-
Tne differen aparationS on Set
Such as unim, intesectico ancd so cm ae
Shawnbela

my-set=i, a3,4
my set-2= 3 4 S -
pan+my-SeEuniom my-set-2)
pin my-Set ntersectimCmy-ot-2)
prin(my-set cdiHerence cmy-set-2)-
pin-ny-sotSymm?tnc-dif-Cmy-set-a-
mu-set. c l e a r (
prin (hny-set-
Onlon ()fumction comblnos darta preseDt M_
bath sets.
inaersection ()Hunctian finds dat prtient o
bath sets
difereacec)unction deletEG clata present
both and autpurts_data pesent enly in set
smmetic difkrehce ()functidn da@s sam2ap
diteen.ce nction but ouputr dataunrb is
emaining o both sets

Ouput
L2,3,4S6G-

Sets-2 @pttton.hub
Dictionar- @python.hub
Dictionanes ane used to store key-ualue pairs-
Key vlue pci is ikophone Dumbers uith
otuct name impllet's understunclmaei
ceatinga Dictianary iE
D create clicfinan we use. curly brae
or use dict functian.

my-dic+:j#empts-diticnary
priint (my-dict
my-dict i pytbon'a: Tava'E elements{
prin my-di
olp hon2 guva-
Deetmq Key Vdle pais
D deete ualues,use Pop ()unctin
unicb_eturnS Ndlue pnat has been cdeleted

my-dicta pythan,2: Tava,aikuby?


a my-dict.popThi #pap elenent
prin Value'i,a
-prm=Dictionany my-dic-
bamy-clict popitem)#E pap keyvalue-pct
protkey, Value pair:, b)_
prin Dictioncnjmy-dict
alp i= Vaue i Ruby-
Dictimaisi Python2mla'
keyVdue pair (fava')
Dictionan Pyth.on-

Accessinq Elements i=
Nou n_access elemeniS usinq -
keyscoly You caneither use g0+U nction
d JusSE pusS h e s y values aocl yauuill be
etieinq the Nelues-

my-dict j'irsHi puhon, 'secmd: cade


pribtmy-clictETHs D#aess usig eys
printCmydlictget C'se.comd
#access elemeot usinq 9et
op Python
Cade

You might also like