0% found this document useful (0 votes)
3 views19 pages

Python Data Structures Overview

The document is a lecture on Python data structures, focusing on arrays and lists. It covers basic operations such as accessing, updating, inserting, and deleting elements in arrays and lists. Additionally, it introduces tuples and sets with references for further learning.

Uploaded by

myatkyalsin10
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)
3 views19 pages

Python Data Structures Overview

The document is a lecture on Python data structures, focusing on arrays and lists. It covers basic operations such as accessing, updating, inserting, and deleting elements in arrays and lists. Additionally, it introduces tuples and sets with references for further learning.

Uploaded by

myatkyalsin10
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

IT

Applied Programming – Python


Part II
Lecture 3

Dr. Nwe Nwe Htay Win


M. C. Sc, University of Computer Studies, Mandalay
Ph.D (IT), China
Harbin Institute of Technology
IT
Outlines
• Python Data structures
• List
• Accessing and Indexing the elements
• Adding new elements
• Deleting the elements
• Updating the elements
IT
Python Data Structures
• Computers store and process data with an extra ordinary speed and
accuracy.
• So, it is highly essential that the data is stored efficiently and can be
accessed fast.
• Also, the processing of data should happen in the smallest possible time,
but without losing the accuracy.
• Data structures deal with how the data is organized and held in the
memory, when a program processes it.
• It is important to note that, the data that is stored in the disk as part of
persistent storages (like relational tables) are not referred as data structure
here.
IT
Array
• Array is a container which can hold a fix number of items and these
items should be of the same type.
• Most of the data structures make use of arrays to implement their
algorithms.
• Following are the important terms to understand the concept of Array.
• Element− Each item stored in an array is called an element.
• Index − Each location of an element in an array has a numerical index, which
is used to identify the element.
IT
Array Presentation

As per the above illustration, following are the important points to be considered.
•Index starts with 0.
•Array length is 10 which means it can store 10 elements.
•Each element can be accessed via its index. For example, we can fetch an element at index 6 as 9.
IT
Basic Operations of Array
• Basic Operations
• Following are the basic operations supported by an array.
• Traverse − print all the array elements one by one.
• Insertion − Adds an element at the given index.
• Deletion − Deletes an element at the given index.
• Search − Searches an element using the given index or by the value.
• Update − Updates an element at the given index.
• Array is created in Python by importing array module to the python program.
Then the array is declared as shown eblow.
IT
Running Python Array
IT
Inserting and Deleting an element in Array
IT
Search / Update Operation in Array
IT
Two Dimensional Array
IT
Python List
• The list is a most versatile datatype available in Python which can be
written as a list of comma-separated values (items) between square
brackets.
• Important thing about a list is that items in a list need not be of the
same type.
• Creating a list is as simple as putting different comma-separated
values between square brackets. For example −
list1 = ['physics', 'chemistry',
1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
list3 = ["a", "b", "c", "d"]
IT
Accessing / Updating the list elements
IT
Deleting/Adding the List Elements
IT
Occurrence and Searching
IT
Sorting the elements of list
IT
Popular Function of List
IT
Tuple and Set
• Reference Link to learn about Tuple
• [Link]
• [Link]
• [Link]
• [Link]

• Reference Link to learn about Set


• [Link]
• [Link]
• [Link]
IT

Let’s Write Python Code


IT
Next Lecture
• Applied Programming- Python – Part III

You might also like