SlideShare a Scribd company logo
1 of 62
Download to read offline
Python Programming
Ali Vaisifard
Inner Data Structures
Inner Data Structures in python
•List
•Tuple
•Dictionary
•Set
List
A container data type that stores a sequence of elements. Unlike
strings, lists are mutable: modification possible. And its
Applications are:
• Used in JSON format
• Useful for Array operations
• Used in Databases
List
• List items are ordered,
changeable, and allow
duplicate values.
• List items are indexed,
the first item has index
[0], the second item has
index [1] etc.
Ordered
• It means that the items have a defined order, and that
order will not change.
• If you add new items to a list, the new items will be
placed at the end of the list.
There are some list methods that will change the order, but in general:
the order of the items will not change.
Changeable
We can change, add, and remove items in a list after it
has been created
Allow Duplicates
Since lists are indexed, lists can have items with the same value:
List Length
len(List_name)
It returns a list length as an integer
List Methods
Lists also get various methods to perform
all operations on list items that called that
methods as “ .method’s name() “ such as
append, remove, pop, delete, insert etc..
You can see all methods called “ dir(list_name)”
All Methods of List Object
1. List_name.append(x)
Add an item to the end of the
list. Equivalent to
List_name[len(List_name):] = [x]
All Methods of List Object
2. List_name.extend(iterable)
Extend the list by appending all the
items from the iterable.
Equivalent to
List_name[len(List_name):] = iterable
All Methods of List Object
3. List_name.insert(i, x)
Insert an item at a given position. The first argument is the
index of the element before which to insert, so
List_name.insert(0, x) inserts at the front of the list, and
List_name.insert(len(a), x) is equivalent to List_name.append(x)
All Methods of List Object
4. List_name.remove(x)
Remove the first item from the list whose value is equal to x
It raises a ValueError if there is no such item.
All Methods of List Object
4. List_name.pop([i])
Remove the item at the given position in the list
and return it. If no index is specified, List_name.pop()
removes and returns the last item in the list.
(The square brackets around the i in the method
signature denote that the parameter is optional, not
that you should type square brackets at the
position.)
All Methods of List Object
5. List_name.clear()
Remove all items from the list.
Equivalent to del List_name[:]
All Methods of List Object
6. List_name.index(x[, start[, end]])
Return zero-based index in the list of the first item whose
value is equal to x. Raises a ValueError if there is no such
item.
The optional arguments start, and end are interpreted as
in the slice notation and are used to limit the search to a
particular subsequence of the list. The returned index is
computed relative to the beginning of the full sequence
rather than the start argument.
All Methods of List Object
7. List_name.count(x)
Return the number of
times x appears in the list.
All Methods of List Object
8. List_name.sort(*, key=None, reverse=False)
Sort the items of the list in place (the
arguments can be used for sort
customization.
All Methods of List Object
9. List_name.reverse()
Reverse the elements of the list in place.
All Methods of List Object
9. List_name.copy()
Return a shallow copy of the list.
Equivalent to List_name[:]
Tuple
• Tuples are Ordered, Unchangeable, allow Duplicate.
• Tuples are created by brackets ()
Ordered
Each items on Tuples has an index number.
Allow Duplicates
Since Tuples are indexed, they can have items with the same value.
Unchangeable
Any items on Tuples could not be removed, added, changed.
Tuple Length
len(tuple_name)
It returns a tuple length as
an integer
All Methods of List Object
1. tuple_name.index(x[, start[, end]])
Searches the tuple for a specified
value and returns the position of
where it was found.
All Methods of Tuple Object
2. tuple_name.count()
Returns the number of
times a specified value
occurs in a tuple
Append two tuples
The addition operation simply
performs a concatenation with
tuples.
You can only add or combine same data
types. Thus, combining a tuple and a list
gives you an error.
Removing items from a tuples
Tuples are immutable. You can't
append to a tuple.
Dictionary
• Dictionaries are used to
store data values in
key: value pairs.
• A dictionary is a
collection which is
ordered*, changeable
and do not allow
duplicates.
• Dictionaries are written
with curly brackets and
have keys and values.
Ordered
Each items on Dictionaries have a defined order, and that order will not change.
Not Allow Duplicates
Dictionaries cannot have two items with the same key.
changeable
we can change, add or remove items after the dictionary has been created.
Dictionary Length
len(dic_name)
To determine
how many
items a
dictionary
has, use this
function.
Dictionary Items - Data Types
The values in dictionary items can be of any data type:
The dict() Constructor
It is also possible to use the dict() constructor to make a
dictionary.
Changing the original dictionary
Change and update the values
Add a new item to the original dictionary
Check if "model" is present in the dictionary
All Methods of Dictionary Object
1. dic_name.get(key)
Get the value of a certain key.
All Methods of Dictionary Object
2. dic_name.keys()
Get a list of the keys.
3. dic_name.Values()
This method will return a
list of all the values in the
dictionary.
4. dic_name.items()
method will return each
item in a dictionary, as
tuples in a list.
All Methods of Dictionary Object
5. dic_name.get(key)
Get the value of a certain key.
All Methods of Dictionary Object
Removing Items:
There are several methods to
remove items from a dictionary:
6. dic_name.pop(key)
The pop() method removes the
item with the specified key name
All Methods of Dictionary Object
7. dic_name.popitem()
The popitem() method removes the last
inserted item
(in versions before 3.7, a random item is
removed instead)
All Methods of Dictionary Object
7. del dic_name[key]
The del keyword removes the item with the
specified key name
8. del dic_name
It can also delete the dictionary completely
All Methods of Dictionary Object
8. dic_name.clear()
The clear() method empties
the dictionary
All Methods of Dictionary Object
Copy a dictionary:
8. dic_name.copy()
Make a copy of a dictionary with the copy() method
9. dic_name2 = dict(dic_name1)
Make a copy of a dictionary with the dict() function
Nested dictionary
A dictionary can contain dictionaries, this is called nested dictionaries.
To access items from a nested dictionary, you use the name of the dictionaries, starting with
the outer dictionary:
Set
• Sets are used to store
multiple items in a
single variable.
• Set items are
unordered,
unchangeable, and do
not allow duplicate
values.
Unordered
Unordered means that the items in a set do not have a defined order.
Set items can appear in a different order every time you use them and cannot be
referred to by index or key.
Not Allow Duplicates
Sets cannot have two items with the same value.
Unchangeable
Set items are unchangeable, meaning that we cannot change the
items after the set has been created.
Different data types
• Set items can be of any data type:
• A set can contain different data types:
The set() Constructor
It is also possible to use the set() constructor to make a set.
Once a set is created, you cannot change its items, but you can add new items.
Sets Length
Duplicate
values will be
ignored:
len(set_name)
The values True and 1, False and 0 are
considered the same value in sets, and
are treated as duplicates
Access Items
You cannot access items in a set by referring to an index or a key.
But you can loop through the set items using a for loop or ask if a specified value is
present in a set, by using the in keyword.
Add Items
• To add one item to a set, use the add() method
Add Sets
• To add items from another set into the current set, use
the update() method.
The object in the update() method does not have to be a set, it can be any iterable
object (tuples, lists, dictionaries etc.).
Remove Item
To remove an item in a set, use the remove(), or the
discard() method.
Note: If the item to remove does not exist, remove() will raise an error, but discard()
will NOT raise an error.
Pop an item
Pop() method to remove an item, but this method will
remove a random item, so you cannot be sure what item that
gets removed.
The return value of the pop() method is the removed item.
Note: Sets are unordered, so when using the pop() method, you do not know which
item that gets removed.
Clear and delete
The clear() method empties the set:
The del keyword will delete the set completely
Join Sets
There are several ways to join two or more sets in Python.
You can use the union() method that returns a new set
containing all items from both sets, or the update() method
that inserts all the items from one set into another
The union() method returns a new set with all items from
both sets
Note: Both union() and update() will exclude any duplicate items.
Keep ONLY the Duplicates
The intersection_update() method will keep only the
items that are present in both sets.
The Intersection() method will return a new set,
that only contains the items that are present in
both sets.
Keep All, But NOT the Duplicates
The symmetric_difference_update() method will keep
only the elements that are NOT present in both sets.
The symmetric_difference()
method will return a new set, that
contains only the elements that are
NOT present in both sets.
All Methods of set Object
Description
Method
Adds an element to the set
add()
Removes all the elements from the set
clear()
Returns a copy of the set
copy()
Returns a set containing the difference between two or more sets
difference()
Removes the items in this set that are also included in another, specified set
difference_update()
Remove the specified item
discard()
Returns a set, that is the intersection of two other sets
intersection()
Removes the items in this set that are not present in other, specified set(s)
intersection_update()
Returns whether two sets have a intersection or not
isdisjoint()
Returns whether another set contains this set or not
issubset()
Returns whether this set contains another set or not
issuperset()
Removes an element from the set
pop()
Removes the specified element
remove()
Returns a set with the symmetric differences of two sets
symmetric_difference()
inserts the symmetric differences from this set and another
symmetric_difference_update()
Return a set containing the union of sets
union()
Update the set with the union of this set and others
update()

More Related Content

Similar to Built-in Data Structures in python 3.pdf

Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)swajahatr
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfalicesilverblr
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfaliracreations
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfadvancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfgiriraj65
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfadityacomputers001
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
Java Amend the LinkedList so that 1 Your list classes must.pdf
Java Amend the LinkedList so that 1 Your list classes must.pdfJava Amend the LinkedList so that 1 Your list classes must.pdf
Java Amend the LinkedList so that 1 Your list classes must.pdfadinathassociates
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAmuthachenthiruK
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptxOut Cast
 
Prompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdfPrompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdfalsofshionchennai
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - JavaDrishti Bhalla
 

Similar to Built-in Data Structures in python 3.pdf (20)

Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4Anton Kasyanov, Introduction to Python, Lecture4
Anton Kasyanov, Introduction to Python, Lecture4
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
 
Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Lists
Lists Lists
Lists
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
Collection Framework-1.pptx
Collection Framework-1.pptxCollection Framework-1.pptx
Collection Framework-1.pptx
 
Python list
Python listPython list
Python list
 
Java Amend the LinkedList so that 1 Your list classes must.pdf
Java Amend the LinkedList so that 1 Your list classes must.pdfJava Amend the LinkedList so that 1 Your list classes must.pdf
Java Amend the LinkedList so that 1 Your list classes must.pdf
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
 
List in Python
List in PythonList in Python
List in Python
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
F sharp lists & dictionary
F sharp   lists &  dictionaryF sharp   lists &  dictionary
F sharp lists & dictionary
 
Prompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdfPrompt Your task is to create a connected list implementation and .pdf
Prompt Your task is to create a connected list implementation and .pdf
 
Collections Api - Java
Collections Api - JavaCollections Api - Java
Collections Api - Java
 

Recently uploaded

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Built-in Data Structures in python 3.pdf

  • 3. Inner Data Structures in python •List •Tuple •Dictionary •Set
  • 4. List A container data type that stores a sequence of elements. Unlike strings, lists are mutable: modification possible. And its Applications are: • Used in JSON format • Useful for Array operations • Used in Databases
  • 5. List • List items are ordered, changeable, and allow duplicate values. • List items are indexed, the first item has index [0], the second item has index [1] etc.
  • 6. Ordered • It means that the items have a defined order, and that order will not change. • If you add new items to a list, the new items will be placed at the end of the list. There are some list methods that will change the order, but in general: the order of the items will not change.
  • 7. Changeable We can change, add, and remove items in a list after it has been created Allow Duplicates Since lists are indexed, lists can have items with the same value:
  • 8. List Length len(List_name) It returns a list length as an integer
  • 9. List Methods Lists also get various methods to perform all operations on list items that called that methods as “ .method’s name() “ such as append, remove, pop, delete, insert etc.. You can see all methods called “ dir(list_name)”
  • 10. All Methods of List Object 1. List_name.append(x) Add an item to the end of the list. Equivalent to List_name[len(List_name):] = [x]
  • 11. All Methods of List Object 2. List_name.extend(iterable) Extend the list by appending all the items from the iterable. Equivalent to List_name[len(List_name):] = iterable
  • 12. All Methods of List Object 3. List_name.insert(i, x) Insert an item at a given position. The first argument is the index of the element before which to insert, so List_name.insert(0, x) inserts at the front of the list, and List_name.insert(len(a), x) is equivalent to List_name.append(x)
  • 13. All Methods of List Object 4. List_name.remove(x) Remove the first item from the list whose value is equal to x It raises a ValueError if there is no such item.
  • 14. All Methods of List Object 4. List_name.pop([i]) Remove the item at the given position in the list and return it. If no index is specified, List_name.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at the position.)
  • 15. All Methods of List Object 5. List_name.clear() Remove all items from the list. Equivalent to del List_name[:]
  • 16. All Methods of List Object 6. List_name.index(x[, start[, end]]) Return zero-based index in the list of the first item whose value is equal to x. Raises a ValueError if there is no such item. The optional arguments start, and end are interpreted as in the slice notation and are used to limit the search to a particular subsequence of the list. The returned index is computed relative to the beginning of the full sequence rather than the start argument.
  • 17. All Methods of List Object 7. List_name.count(x) Return the number of times x appears in the list.
  • 18. All Methods of List Object 8. List_name.sort(*, key=None, reverse=False) Sort the items of the list in place (the arguments can be used for sort customization.
  • 19. All Methods of List Object 9. List_name.reverse() Reverse the elements of the list in place.
  • 20. All Methods of List Object 9. List_name.copy() Return a shallow copy of the list. Equivalent to List_name[:]
  • 21. Tuple • Tuples are Ordered, Unchangeable, allow Duplicate. • Tuples are created by brackets ()
  • 22. Ordered Each items on Tuples has an index number. Allow Duplicates Since Tuples are indexed, they can have items with the same value. Unchangeable Any items on Tuples could not be removed, added, changed.
  • 23. Tuple Length len(tuple_name) It returns a tuple length as an integer
  • 24. All Methods of List Object 1. tuple_name.index(x[, start[, end]]) Searches the tuple for a specified value and returns the position of where it was found.
  • 25. All Methods of Tuple Object 2. tuple_name.count() Returns the number of times a specified value occurs in a tuple
  • 26. Append two tuples The addition operation simply performs a concatenation with tuples. You can only add or combine same data types. Thus, combining a tuple and a list gives you an error.
  • 27. Removing items from a tuples Tuples are immutable. You can't append to a tuple.
  • 28. Dictionary • Dictionaries are used to store data values in key: value pairs. • A dictionary is a collection which is ordered*, changeable and do not allow duplicates. • Dictionaries are written with curly brackets and have keys and values.
  • 29. Ordered Each items on Dictionaries have a defined order, and that order will not change. Not Allow Duplicates Dictionaries cannot have two items with the same key. changeable we can change, add or remove items after the dictionary has been created.
  • 30. Dictionary Length len(dic_name) To determine how many items a dictionary has, use this function.
  • 31. Dictionary Items - Data Types The values in dictionary items can be of any data type:
  • 32. The dict() Constructor It is also possible to use the dict() constructor to make a dictionary.
  • 33. Changing the original dictionary
  • 34. Change and update the values
  • 35. Add a new item to the original dictionary
  • 36. Check if "model" is present in the dictionary
  • 37. All Methods of Dictionary Object 1. dic_name.get(key) Get the value of a certain key.
  • 38. All Methods of Dictionary Object 2. dic_name.keys() Get a list of the keys. 3. dic_name.Values() This method will return a list of all the values in the dictionary. 4. dic_name.items() method will return each item in a dictionary, as tuples in a list.
  • 39. All Methods of Dictionary Object 5. dic_name.get(key) Get the value of a certain key.
  • 40. All Methods of Dictionary Object Removing Items: There are several methods to remove items from a dictionary: 6. dic_name.pop(key) The pop() method removes the item with the specified key name
  • 41. All Methods of Dictionary Object 7. dic_name.popitem() The popitem() method removes the last inserted item (in versions before 3.7, a random item is removed instead)
  • 42. All Methods of Dictionary Object 7. del dic_name[key] The del keyword removes the item with the specified key name 8. del dic_name It can also delete the dictionary completely
  • 43. All Methods of Dictionary Object 8. dic_name.clear() The clear() method empties the dictionary
  • 44.
  • 45. All Methods of Dictionary Object Copy a dictionary: 8. dic_name.copy() Make a copy of a dictionary with the copy() method 9. dic_name2 = dict(dic_name1) Make a copy of a dictionary with the dict() function
  • 46. Nested dictionary A dictionary can contain dictionaries, this is called nested dictionaries. To access items from a nested dictionary, you use the name of the dictionaries, starting with the outer dictionary:
  • 47. Set • Sets are used to store multiple items in a single variable. • Set items are unordered, unchangeable, and do not allow duplicate values.
  • 48. Unordered Unordered means that the items in a set do not have a defined order. Set items can appear in a different order every time you use them and cannot be referred to by index or key. Not Allow Duplicates Sets cannot have two items with the same value. Unchangeable Set items are unchangeable, meaning that we cannot change the items after the set has been created.
  • 49. Different data types • Set items can be of any data type: • A set can contain different data types:
  • 50. The set() Constructor It is also possible to use the set() constructor to make a set. Once a set is created, you cannot change its items, but you can add new items.
  • 51. Sets Length Duplicate values will be ignored: len(set_name)
  • 52. The values True and 1, False and 0 are considered the same value in sets, and are treated as duplicates
  • 53. Access Items You cannot access items in a set by referring to an index or a key. But you can loop through the set items using a for loop or ask if a specified value is present in a set, by using the in keyword.
  • 54. Add Items • To add one item to a set, use the add() method
  • 55. Add Sets • To add items from another set into the current set, use the update() method. The object in the update() method does not have to be a set, it can be any iterable object (tuples, lists, dictionaries etc.).
  • 56. Remove Item To remove an item in a set, use the remove(), or the discard() method. Note: If the item to remove does not exist, remove() will raise an error, but discard() will NOT raise an error.
  • 57. Pop an item Pop() method to remove an item, but this method will remove a random item, so you cannot be sure what item that gets removed. The return value of the pop() method is the removed item. Note: Sets are unordered, so when using the pop() method, you do not know which item that gets removed.
  • 58. Clear and delete The clear() method empties the set: The del keyword will delete the set completely
  • 59. Join Sets There are several ways to join two or more sets in Python. You can use the union() method that returns a new set containing all items from both sets, or the update() method that inserts all the items from one set into another The union() method returns a new set with all items from both sets Note: Both union() and update() will exclude any duplicate items.
  • 60. Keep ONLY the Duplicates The intersection_update() method will keep only the items that are present in both sets. The Intersection() method will return a new set, that only contains the items that are present in both sets.
  • 61. Keep All, But NOT the Duplicates The symmetric_difference_update() method will keep only the elements that are NOT present in both sets. The symmetric_difference() method will return a new set, that contains only the elements that are NOT present in both sets.
  • 62. All Methods of set Object Description Method Adds an element to the set add() Removes all the elements from the set clear() Returns a copy of the set copy() Returns a set containing the difference between two or more sets difference() Removes the items in this set that are also included in another, specified set difference_update() Remove the specified item discard() Returns a set, that is the intersection of two other sets intersection() Removes the items in this set that are not present in other, specified set(s) intersection_update() Returns whether two sets have a intersection or not isdisjoint() Returns whether another set contains this set or not issubset() Returns whether this set contains another set or not issuperset() Removes an element from the set pop() Removes the specified element remove() Returns a set with the symmetric differences of two sets symmetric_difference() inserts the symmetric differences from this set and another symmetric_difference_update() Return a set containing the union of sets union() Update the set with the union of this set and others update()