SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
Data Structures-1
Prof. K. Adisesha
BE, M.Sc., M.Th., NET, (Ph.D.)
2
Learning objectives
• Introduction
• Data Structure Types
 Primitive Data Structure
 Non-Primitive Data Structure
• List Manipulations
• Data Structure Operations
3
Data Structure
What is Data Structure ?
• Data structures are a way of organizing and storing data so
that they can be accessed and worked with efficiently.
• Data structures and algorithms are closely related
 Representation and organization of data
 Facilitate access and modification of data
 Different data structures have strengths and weaknesses
 Better suited for a specific algorithm than others
4
Data Structure
Data Structure using Python
• We will use Python as programming language
• Data structures and algorithms are independent of
programming language
 This is not a basic programming course
 We focus on higher level issues
 You should already have experience with a programming
language (Python, Java, C/C++)
5
Data Structure
Classification of Data Structure
• In the traditional computer science world, the Data structures are
divided into:
6
Data Structure
Primitive Data Structures
• These are the most primitive or the basic data structures.
• They are the building blocks for data manipulation and
contain pure, simple values of a data.
• Python has four primitive variable types:
 Integers
 Float
 Strings
 Boolean
7
Data Structure
Non-Primitive Data Structures
• Non-Primitive Data Structures are the sophisticated
members of the data structure family.
• They don't just store a value, but rather a collection of
values in various formats.
• In the traditional computer science world, the non-primitive
data structures are divided into:
 Arrays
 Lists
 Tuples
 Dictionary
 Sets
 Files
8
Data Structure
Types of Data Structures in Python
• Built-in Data Structures
• User-Defined Data Structures
9
Data Structure
Built-in Data Structures
• Data Structures are built-in with Python which makes
programming easier and helps programmers use them to
obtain solutions faster.
• Built-in Data Structures in Python
 List
 Dictionary
 Tuple
 Sets
10
List
LIST
• Lists in Python are used to store collection of heterogeneous
items.
• These are mutable, which means that you can change their
content without changing their identity.
• You can recognize lists by their square brackets [ and ] that hold
elements, separated by a comma ,.
• There are addresses assigned to every element of the list, which
is called as Index.
• The index value starts from 0 and goes on until the last element
called the positive index.
• There is also negative indexing which starts from -1 enabling you
to access elements from the last to first.
11
List Manipulation
List Manipulation
• Python provides many methods to manipulate and work with lists.
• Common list manipulations Functions are:
 Adding new items to a list,
 Removing some items from a list,
 Sorting or reversing a list are.
 Find length of the list.
 Find the index value of value passed in List.
 Find the count of the value passed to List.
12
List Manipulation
Adding Elements
• Adding the elements in the list can be achieved using:
 append() function
 extend() function
 insert() function
13
List Manipulation
append() function
• The append() function adds all the elements passed to it as
a single element.
• Example:
my_list = [1, 2, 3]
print(my_list)
my_list.append([4, 5,6]) #add as a single element
print(my_list)
 Output:
[1, 2, 3]
[1, 2, 3, [4, 5, 6]]
14
List Manipulation
extend() function
• The extend() function adds the elements one-by-one into
the list.
• Example:
my_list = [1, 2, 3]
print(my_list)
my_list.extend([4, 5]) #add as different elements
print(my_list)
 Output:
[1, 2, 3]
[1, 2, 3, 4, 5]
15
List Manipulation
insert() function
• The insert() function adds the element passed to the index
value and increase the size of the list too.
• Example:
my_list = [1, 2, 3]
print(my_list)
my_list.insert(1, ‘Sunny') #add element at 1
print(my_list)
 Output:
[1, 2, 3]
[1, ‘Sunny’, 2, 3, 4, 5]
16
List Manipulation
Deleting Elements
• del keyword
 To delete elements, use the del keyword which is built-in
into Python but this does not return anything back to us.
• pop() function
 If you want the element back, you use the pop() function
which takes the index value.
• remove() function.
 To remove an element by its value, you use the remove()
function.
• clear() function
 To remove all elements from the list, to make an empty list
we use the clear() function.
17
List Manipulation
del keyword
• To delete elements, use the del keyword which is built-in
into Python but this does not return anything back to us.
• Example:
my_list = [10, ‘Sunny’, 20, 30, 40, 50]
print(my_list)
del my_list[5] #delete element at index 4
print(my_list)
 Output:
[10, ‘Sunny’, 20, 30, 40, 50]
[10, ‘Sunny’, 20, 30, 50] #after deleting index 4
18
List Manipulation
pop() function
• If you want the element back, you use the pop() function
which takes the index value.
• Example:
my_list = [10, ‘Sunny’, 20, 30, 40, 50]
print(my_list)
a = my_list.pop(1) #pop element from list
print('Popped Element: ', a, ' List remaining: ', my_list)
 Output:
[10, ‘Sunny’, 20, 30, 40, 50]
'Popped Element: Sunny List remaining: [10, 20, 30, 40, 50]
19
List Manipulation
remove() function
• To remove an element by its value, you use the remove()
function.
• Example:
my_list = [10, ‘Sunny’, 20, 30, 40, 50]
print(my_list)
my_list.remove(‘Sunny') #remove element with value
print(my_list)
 Output:
[10, ‘Sunny’, 20, 30, 40, 50]
[10, 20, 30, 40, 50] #after deleting ‘Sunny’
20
List Manipulation
clear() function
• To remove all elements from the list, to make an empty list
we use the clear() function.
• Example:
my_list = [10, ‘Sunny’, 20, 30, 40, 50]
print(my_list)
my_list.clear() #empty the list
print(my_list)
 Output:
[10, ‘Sunny’, 20, 30, 40, 50]
[ ] #empty the list
21
List Manipulation
Accessing Elements
• Accessing elements from a List is done by range of indexes
by specifying start and end position of the range.
• When specifying a range, the return value will be a new list
with the specified items.
• Example:
my_list = [10, 20, 30, 40, 50]
for element in my_list: #access elements one by one
print(element)
Output:
10, 20, 30, 40, 50
22
List Manipulation
Accessing Elements
• You pass the index values and hence can obtain the values
as needed.
• Example:
my_list = [10, [‘Sunny’, 20, 30, 40], 50]
print(my_list)
Output: [10, [‘Sunny’, 20, 30, 40], 50]
len(my_list)
Output: 3
print(my_list[1])
Output: [‘Sunny’, 20, 30, 40]
print([1][0])
Output: [‘Sunny’]
print([1][0][-4])
Output: ’u’
23
List Manipulation
Copy a List:
• There are ways to make a copy, one-way is to use the built-in copy(),
list() method.
• copy() method: Make a copy of a list:
 Example
StuList = ["Prajwal", "Sunny", "Rekha"]
mylist = StuList.copy()
print(mylist)
Output: ['Prajwal', 'Sunny', 'Rekha']
• list() method: Make a copy of a list:
 Example
StuList = ["Prajwal", "Sunny", "Rekha"]
mylist = list(StuList)
print(mylist)
Output: ['Prajwal', 'Sunny', 'Rekha']
24
List Manipulation
Count(): You can count the number of element of a kind:
 Example
my_list = [10, 20, 10, 40, 10]
my_list.count(10)
Output: 3
Sort(): There is a sort() method that performs an in-place sorting:
 Example
StuList = my_list = [10, 20, 10, 40, 10]
my_list.sort()
print(my_list)
Output: [10, 10, 10, 20, 40]
Reverse: Finally, you can reverse the element in-place:
 Example
my_list = ['a', 'c' ,'b']
my_list.reverse()
print(my_list)
Output: ['b', 'c', 'a']
25
List Methods
Built-in Python list methods
• Following is the table containing the set of built-in methods that you can
use on List.
Method Description
append() It adds a new element to the end of the list.
extend() It extends a list by adding elements from another list.
insert() It injects a new element at the desired index.
remove() It deletes the desired element from the list.
pop() It removes as well as returns an item from the given position.
clear() It flushes out all elements of a list.
count() It returns the total no. of elements passed as an argument.
sort() It orders the elements of a list in an ascending manner.
reverse() It inverts the order of the elements in a list.
copy() It performs a shallow copy of the list and returns.
len() The return value is the size of the list.
26
SEARCHING
SEARCHING ALGORITHMS
27
SORTING
SORTING ALGORITHMS
28
• We learned about:
 Data Structure Definition
 Data Structure Types
 Primitive Data Structure
 Non-Primitive Data Structure
 List Manipulations
 Data Structure Operations
Thank you
Conclusion!

Mais conteúdo relacionado

Mais procurados (20)

Pandas csv
Pandas csvPandas csv
Pandas csv
 
Java ArrayList Tutorial | Edureka
Java ArrayList Tutorial | EdurekaJava ArrayList Tutorial | Edureka
Java ArrayList Tutorial | Edureka
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
NUMPY
NUMPY NUMPY
NUMPY
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Python collections
Python collectionsPython collections
Python collections
 
List in Python
List in PythonList in Python
List in Python
 
List in Python
List in PythonList in Python
List in Python
 
Lists
ListsLists
Lists
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Data structure
Data structureData structure
Data structure
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
Queue
QueueQueue
Queue
 

Semelhante a 8 python data structure-1

Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsSreedhar Chowdam
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology InitiativeBasil Bibi
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptxOut Cast
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_pythondeepalishinkar1
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptxASRPANDEY
 
Python programming
Python programmingPython programming
Python programmingsirikeshava
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptxSakith1
 
Python List.ppt
Python List.pptPython List.ppt
Python List.pptT PRIYA
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189Mahmoud Samir Fayed
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
lists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptxlists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptxShanthiJeyabal
 

Semelhante a 8 python data structure-1 (20)

updated_list.pptx
updated_list.pptxupdated_list.pptx
updated_list.pptx
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
Python lists
Python listsPython lists
Python lists
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Python list
Python listPython list
Python list
 
Python for Beginners(v3)
Python for Beginners(v3)Python for Beginners(v3)
Python for Beginners(v3)
 
Python programming
Python programmingPython programming
Python programming
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
 
Python List.ppt
Python List.pptPython List.ppt
Python List.ppt
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Python list
Python listPython list
Python list
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
 
CH05.ppt
CH05.pptCH05.ppt
CH05.ppt
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
lists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptxlists_list_of_liststuples_of_python.pptx
lists_list_of_liststuples_of_python.pptx
 

Mais de Prof. Dr. K. Adisesha

Software Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfSoftware Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfSoftware Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfSoftware Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfSoftware Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfSoftware Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfProf. Dr. K. Adisesha
 
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfSoftware Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfProf. Dr. K. Adisesha
 
Computer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaComputer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaProf. Dr. K. Adisesha
 
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaCCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaProf. Dr. K. Adisesha
 
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaCCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaProf. Dr. K. Adisesha
 
CCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaCCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaProf. Dr. K. Adisesha
 
CCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfCCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfProf. Dr. K. Adisesha
 

Mais de Prof. Dr. K. Adisesha (20)

Software Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdfSoftware Engineering notes by K. Adisesha.pdf
Software Engineering notes by K. Adisesha.pdf
 
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdfSoftware Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdf
 
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdfSoftware Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
 
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdfSoftware Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
 
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdfSoftware Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
 
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdfSoftware Engineering-Unit 5 "Software Testing"by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
 
Computer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. AdiseshaComputer Networks Notes by -Dr. K. Adisesha
Computer Networks Notes by -Dr. K. Adisesha
 
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. AdiaeshaCCN Unit-1&2 Data Communication &Networking by K. Adiaesha
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
 
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. AdiseshaCCN Unit-3 Data Link Layer by Dr. K. Adisesha
CCN Unit-3 Data Link Layer by Dr. K. Adisesha
 
CCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. AdiseshaCCN Unit-4 Network Layer by Dr. K. Adisesha
CCN Unit-4 Network Layer by Dr. K. Adisesha
 
CCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdfCCN Unit-5 Transport & Application Layer by Adi.pdf
CCN Unit-5 Transport & Application Layer by Adi.pdf
 
Introduction to Computers.pdf
Introduction to Computers.pdfIntroduction to Computers.pdf
Introduction to Computers.pdf
 
R_Programming.pdf
R_Programming.pdfR_Programming.pdf
R_Programming.pdf
 
Scholarship.pdf
Scholarship.pdfScholarship.pdf
Scholarship.pdf
 
Operating System-2 by Adi.pdf
Operating System-2 by Adi.pdfOperating System-2 by Adi.pdf
Operating System-2 by Adi.pdf
 
Operating System-1 by Adi.pdf
Operating System-1 by Adi.pdfOperating System-1 by Adi.pdf
Operating System-1 by Adi.pdf
 
Operating System-adi.pdf
Operating System-adi.pdfOperating System-adi.pdf
Operating System-adi.pdf
 
Data_structure using C-Adi.pdf
Data_structure using C-Adi.pdfData_structure using C-Adi.pdf
Data_structure using C-Adi.pdf
 
JAVA PPT -2 BY ADI.pdf
JAVA PPT -2 BY ADI.pdfJAVA PPT -2 BY ADI.pdf
JAVA PPT -2 BY ADI.pdf
 
JAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdfJAVA PPT -5 BY ADI.pdf
JAVA PPT -5 BY ADI.pdf
 

Último

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

8 python data structure-1

  • 1. Data Structures-1 Prof. K. Adisesha BE, M.Sc., M.Th., NET, (Ph.D.)
  • 2. 2 Learning objectives • Introduction • Data Structure Types  Primitive Data Structure  Non-Primitive Data Structure • List Manipulations • Data Structure Operations
  • 3. 3 Data Structure What is Data Structure ? • Data structures are a way of organizing and storing data so that they can be accessed and worked with efficiently. • Data structures and algorithms are closely related  Representation and organization of data  Facilitate access and modification of data  Different data structures have strengths and weaknesses  Better suited for a specific algorithm than others
  • 4. 4 Data Structure Data Structure using Python • We will use Python as programming language • Data structures and algorithms are independent of programming language  This is not a basic programming course  We focus on higher level issues  You should already have experience with a programming language (Python, Java, C/C++)
  • 5. 5 Data Structure Classification of Data Structure • In the traditional computer science world, the Data structures are divided into:
  • 6. 6 Data Structure Primitive Data Structures • These are the most primitive or the basic data structures. • They are the building blocks for data manipulation and contain pure, simple values of a data. • Python has four primitive variable types:  Integers  Float  Strings  Boolean
  • 7. 7 Data Structure Non-Primitive Data Structures • Non-Primitive Data Structures are the sophisticated members of the data structure family. • They don't just store a value, but rather a collection of values in various formats. • In the traditional computer science world, the non-primitive data structures are divided into:  Arrays  Lists  Tuples  Dictionary  Sets  Files
  • 8. 8 Data Structure Types of Data Structures in Python • Built-in Data Structures • User-Defined Data Structures
  • 9. 9 Data Structure Built-in Data Structures • Data Structures are built-in with Python which makes programming easier and helps programmers use them to obtain solutions faster. • Built-in Data Structures in Python  List  Dictionary  Tuple  Sets
  • 10. 10 List LIST • Lists in Python are used to store collection of heterogeneous items. • These are mutable, which means that you can change their content without changing their identity. • You can recognize lists by their square brackets [ and ] that hold elements, separated by a comma ,. • There are addresses assigned to every element of the list, which is called as Index. • The index value starts from 0 and goes on until the last element called the positive index. • There is also negative indexing which starts from -1 enabling you to access elements from the last to first.
  • 11. 11 List Manipulation List Manipulation • Python provides many methods to manipulate and work with lists. • Common list manipulations Functions are:  Adding new items to a list,  Removing some items from a list,  Sorting or reversing a list are.  Find length of the list.  Find the index value of value passed in List.  Find the count of the value passed to List.
  • 12. 12 List Manipulation Adding Elements • Adding the elements in the list can be achieved using:  append() function  extend() function  insert() function
  • 13. 13 List Manipulation append() function • The append() function adds all the elements passed to it as a single element. • Example: my_list = [1, 2, 3] print(my_list) my_list.append([4, 5,6]) #add as a single element print(my_list)  Output: [1, 2, 3] [1, 2, 3, [4, 5, 6]]
  • 14. 14 List Manipulation extend() function • The extend() function adds the elements one-by-one into the list. • Example: my_list = [1, 2, 3] print(my_list) my_list.extend([4, 5]) #add as different elements print(my_list)  Output: [1, 2, 3] [1, 2, 3, 4, 5]
  • 15. 15 List Manipulation insert() function • The insert() function adds the element passed to the index value and increase the size of the list too. • Example: my_list = [1, 2, 3] print(my_list) my_list.insert(1, ‘Sunny') #add element at 1 print(my_list)  Output: [1, 2, 3] [1, ‘Sunny’, 2, 3, 4, 5]
  • 16. 16 List Manipulation Deleting Elements • del keyword  To delete elements, use the del keyword which is built-in into Python but this does not return anything back to us. • pop() function  If you want the element back, you use the pop() function which takes the index value. • remove() function.  To remove an element by its value, you use the remove() function. • clear() function  To remove all elements from the list, to make an empty list we use the clear() function.
  • 17. 17 List Manipulation del keyword • To delete elements, use the del keyword which is built-in into Python but this does not return anything back to us. • Example: my_list = [10, ‘Sunny’, 20, 30, 40, 50] print(my_list) del my_list[5] #delete element at index 4 print(my_list)  Output: [10, ‘Sunny’, 20, 30, 40, 50] [10, ‘Sunny’, 20, 30, 50] #after deleting index 4
  • 18. 18 List Manipulation pop() function • If you want the element back, you use the pop() function which takes the index value. • Example: my_list = [10, ‘Sunny’, 20, 30, 40, 50] print(my_list) a = my_list.pop(1) #pop element from list print('Popped Element: ', a, ' List remaining: ', my_list)  Output: [10, ‘Sunny’, 20, 30, 40, 50] 'Popped Element: Sunny List remaining: [10, 20, 30, 40, 50]
  • 19. 19 List Manipulation remove() function • To remove an element by its value, you use the remove() function. • Example: my_list = [10, ‘Sunny’, 20, 30, 40, 50] print(my_list) my_list.remove(‘Sunny') #remove element with value print(my_list)  Output: [10, ‘Sunny’, 20, 30, 40, 50] [10, 20, 30, 40, 50] #after deleting ‘Sunny’
  • 20. 20 List Manipulation clear() function • To remove all elements from the list, to make an empty list we use the clear() function. • Example: my_list = [10, ‘Sunny’, 20, 30, 40, 50] print(my_list) my_list.clear() #empty the list print(my_list)  Output: [10, ‘Sunny’, 20, 30, 40, 50] [ ] #empty the list
  • 21. 21 List Manipulation Accessing Elements • Accessing elements from a List is done by range of indexes by specifying start and end position of the range. • When specifying a range, the return value will be a new list with the specified items. • Example: my_list = [10, 20, 30, 40, 50] for element in my_list: #access elements one by one print(element) Output: 10, 20, 30, 40, 50
  • 22. 22 List Manipulation Accessing Elements • You pass the index values and hence can obtain the values as needed. • Example: my_list = [10, [‘Sunny’, 20, 30, 40], 50] print(my_list) Output: [10, [‘Sunny’, 20, 30, 40], 50] len(my_list) Output: 3 print(my_list[1]) Output: [‘Sunny’, 20, 30, 40] print([1][0]) Output: [‘Sunny’] print([1][0][-4]) Output: ’u’
  • 23. 23 List Manipulation Copy a List: • There are ways to make a copy, one-way is to use the built-in copy(), list() method. • copy() method: Make a copy of a list:  Example StuList = ["Prajwal", "Sunny", "Rekha"] mylist = StuList.copy() print(mylist) Output: ['Prajwal', 'Sunny', 'Rekha'] • list() method: Make a copy of a list:  Example StuList = ["Prajwal", "Sunny", "Rekha"] mylist = list(StuList) print(mylist) Output: ['Prajwal', 'Sunny', 'Rekha']
  • 24. 24 List Manipulation Count(): You can count the number of element of a kind:  Example my_list = [10, 20, 10, 40, 10] my_list.count(10) Output: 3 Sort(): There is a sort() method that performs an in-place sorting:  Example StuList = my_list = [10, 20, 10, 40, 10] my_list.sort() print(my_list) Output: [10, 10, 10, 20, 40] Reverse: Finally, you can reverse the element in-place:  Example my_list = ['a', 'c' ,'b'] my_list.reverse() print(my_list) Output: ['b', 'c', 'a']
  • 25. 25 List Methods Built-in Python list methods • Following is the table containing the set of built-in methods that you can use on List. Method Description append() It adds a new element to the end of the list. extend() It extends a list by adding elements from another list. insert() It injects a new element at the desired index. remove() It deletes the desired element from the list. pop() It removes as well as returns an item from the given position. clear() It flushes out all elements of a list. count() It returns the total no. of elements passed as an argument. sort() It orders the elements of a list in an ascending manner. reverse() It inverts the order of the elements in a list. copy() It performs a shallow copy of the list and returns. len() The return value is the size of the list.
  • 28. 28 • We learned about:  Data Structure Definition  Data Structure Types  Primitive Data Structure  Non-Primitive Data Structure  List Manipulations  Data Structure Operations Thank you Conclusion!