Python Data Structures
Python Data Structures
DATA
STRUCTURES
SHOOLINI
UNIVERSITY
DANIEL RIZVI
WHAT ARE DATA STRUCTURES?
WHAT ARE DATA STRUCTURES
WHAT ARE DATA STRUCTURES
WHAT ARE DATA STRUCTURES
They are structures which can hold
some data together. In other words,
they are used to store a collection of
related data.
THERE ARE FOUR BUILT-IN DATA
STRUCTURES IN PYTHON
[] ([]) () {}
IVZIR
LEINAD
LIST
A LIST IS A DATA STRUCTURE IN PYTHON THAT
IS A MUTABLE, OR CHANGEABLE, ORDERED
SEQUENCE OF ELEMENTS
PYTHON
LOOKING AT THE EXAMPLES
IVZIR
LEINAD
ADDING TO THE LIST
shoplist = ['soap','cake','shampoo','pen']
shoplist.append('glasses')
print(shoplist)
D
OUTPUT -
['soap', 'cake', 'shampoo', 'pen', 'glasses']
PYTHON
*append - is the keyword used to add item in the list
LOOKING AT THE EXAMPLES
IVZIR
LEINAD
TO REMOVE ITEM FROM THE LIST
shoplist = ['soap','cake','shampoo','pen','glasses']
print(shoplist.remove('cake'))
print(shoplist)
D
OUTPUT -
['soap', 'shampoo', 'pen', 'glasses']
PYTHON
*remove - is the keyword used to remove item in the list
LOOKING AT THE EXAMPLES sham
soap cake pen
IVZIR
poo
LEINAD
TO PRINT THE INDEX
0 1 2 3
shoplist = ['soap','cake','shampoo','pen','glasses']
shoplist.index('cake')
print(shoplist)
OUTPUT - D
PYTHON
and returns the lowest index where the element appears
LOOKING AT THE EXAMPLES sham
soap cake pen
IVZIR
poo
LEINAD
IN A LIST, THE 2NDAND 3RD ITEMS
CAN BE ACCESSED WITH: 0 1 2 3
shoplist = ['soap','cake','shampoo','pen','glasses']
print(shoplist[1:3]))
OUTPUT - D
['cake', 'shampoo']
PYTHON
and returns the lowest index where the element appears
tuple( )
A Tuple is a collection of Python objects separated
by commas. In someways a tuple is similar to a list
in terms of indexing, nested objects and repetition
but a tuple is immutable unlike lists which are
mutable.
tuple is immutable
we can't make changes
tuple example
mytuple = (21,44,11)
print(mylist)
output-
COMPONENTS OF DICTIONARY
GRADE = {"RAMESH":89}
key value
EXAMPLE OF DICTIONARY
GRADE = {"SURAJ":90,"SURYA":91,"ANMOL":92,"ANIL":77}
PRINT(GRADE)
OUTPUT-
{'SURAJ': 90, 'SURYA': 91, 'ANMOL': 92, 'ANIL': 77}
*dictionary is mutable
EXAMPLE OF DICTIONARY
CALLING BY KEY
GRADE = {"SURAJ":90,"SURYA":91,"ANMOL":92,"ANIL":77}
PRINT(GRADE["SURAJ"])
OUTPUT-
90
OUTPUT FORMAT-
True
set([]) {}
sets dictionary
A set is an unordered collection of A dictionary is
items. a set itself is mutable. a key:value pair, Dictionaries themselv
es are mutable
thank you
DANIEL RIZVI