SlideShare a Scribd company logo
Module 2
Data Collections – Lists, Tuples,
and Dictionaries
Sorting simple lists
Module 2 Sorting simple lists
Bubble sort
8 10 6 2 4
8 6 10 2 4
8 6 2 10 4
8 6 2 4 10
6 8 2 4 10
6 2 8 4 10
6 2 4 8 10
2 6 4 8 10
2 4 6 8 10
Increasing order
Module 2 Sorting simple lists
Sorting a list
my_list = [8, 10, 6, 2, 4] # list to sort
swapped = True # It's a little fake, we need it to enter the while loop.
while swapped:
swapped = False # no swaps so far
for i in range(len(my_list) - 1):
if my_list[i] > my_list[i + 1]:
swapped = True # a swap occurred!
my_list[i], my_list[i + 1] = my_list[i + 1], my_list[i]
print(my_list)
Module 2 Sorting simple lists
Ready-to-use tools
Python has its own
sorting mechanisms: .sort()
my_list = [8, 10, 6, 2, 4] # list to sort
swapped = True # It's a little fake, we need it to enter the while loop.
my_list.sort()
print(my_list)
Module 2 Sorting simple lists
Key takeaways
sort()
•to sort elements
of a list
reverse()
•to reverse the list
Ad

Recommended

PDF
1. python
PRASHANT OJHA
 
PPTX
More About Strings
Munazza-Mah-Jabeen
 
PPTX
Learn python - for beginners - part-2
RajKumar Rampelli
 
PPTX
Brixton Library Technology Initiative
Basil Bibi
 
PPTX
Python 101++: Let's Get Down to Business!
Paige Bailey
 
PPTX
Python PCEP Functions And Scopes
IHTMINSTITUTE
 
PPTX
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
PPT
Oop lecture7
Shahriar Robbani
 
PDF
Learn 90% of Python in 90 Minutes
Matt Harrison
 
PDF
Matlab and Python: Basic Operations
Wai Nwe Tun
 
PPTX
Macrobrew: Clojure macros distilled
abhinavomprakash10
 
PDF
Python dictionary : past, present, future
delimitry
 
PPTX
Datastructures in python
hydpy
 
PPTX
Basic data structures in python
Celine George
 
PPTX
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
PPTX
Dictionaries and Sets in Python
Raajendra M
 
PPTX
16 containers
dhrubo kayal
 
PDF
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
PPTX
Session 05 cleaning and exploring
bodaceacat
 
PPTX
Session 02 python basics
bodaceacat
 
PPTX
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
PPTX
Basics of Python programming (part 2)
Pedro Rodrigues
 
PPTX
Python Traning presentation
Nimrita Koul
 
PPTX
day 13.pptx
codewavecommunity44
 
PPTX
Python programming Sequence Datatypes -Tuples
BushraKm2
 
PPTX
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
PPTX
1.4 Sorting.pptx
Sujan527908
 

More Related Content

What's hot (18)

PPT
Oop lecture7
Shahriar Robbani
 
PDF
Learn 90% of Python in 90 Minutes
Matt Harrison
 
PDF
Matlab and Python: Basic Operations
Wai Nwe Tun
 
PPTX
Macrobrew: Clojure macros distilled
abhinavomprakash10
 
PDF
Python dictionary : past, present, future
delimitry
 
PPTX
Datastructures in python
hydpy
 
PPTX
Basic data structures in python
Celine George
 
PPTX
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
PPTX
Dictionaries and Sets in Python
Raajendra M
 
PPTX
16 containers
dhrubo kayal
 
PDF
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
PPTX
Session 05 cleaning and exploring
bodaceacat
 
PPTX
Session 02 python basics
bodaceacat
 
PPTX
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
PPTX
Basics of Python programming (part 2)
Pedro Rodrigues
 
PPTX
Python Traning presentation
Nimrita Koul
 
Oop lecture7
Shahriar Robbani
 
Learn 90% of Python in 90 Minutes
Matt Harrison
 
Matlab and Python: Basic Operations
Wai Nwe Tun
 
Macrobrew: Clojure macros distilled
abhinavomprakash10
 
Python dictionary : past, present, future
delimitry
 
Datastructures in python
hydpy
 
Basic data structures in python
Celine George
 
FUNCTIONS IN PYTHON. CBSE +2 COMPUTER SCIENCE
Venugopalavarma Raja
 
Dictionaries and Sets in Python
Raajendra M
 
16 containers
dhrubo kayal
 
Python fundamentals - basic | WeiYuan
Wei-Yuan Chang
 
Session 05 cleaning and exploring
bodaceacat
 
Session 02 python basics
bodaceacat
 
Python PCEP Lists Collections of Data
IHTMINSTITUTE
 
Basics of Python programming (part 2)
Pedro Rodrigues
 
Python Traning presentation
Nimrita Koul
 

Similar to Python PCEP Sorting Simple Lists (20)

PPTX
day 13.pptx
codewavecommunity44
 
PPTX
Python programming Sequence Datatypes -Tuples
BushraKm2
 
PPTX
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
PPTX
1.4 Sorting.pptx
Sujan527908
 
PPTX
Lecture 13 data structures and algorithms
Aakash deep Singhal
 
PPTX
Unit III Version I.pptx
ssuserd602fd
 
PPTX
Part 2 - Python Tutorial | Introduction to Lists
Shivam Mitra
 
PDF
Chapter 5 searching and sorting handouts with notes
mailund
 
PPTX
SORTING techniques.pptx
Dr.Shweta
 
PDF
Python - Lecture 10
Ravi Kiran Khareedi
 
PPTX
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
tahliildhoore54
 
PPTX
Sorting method data structure
sunilchute1
 
PPT
Sorting algorithm
Muhammad Farhan
 
PDF
Python programing basic knowledge hh.pdf
raviofficialmrm06
 
PDF
L 14-ct1120
Zia Ush Shamszaman
 
PPTX
Data Structures and Algorithms
Mark Jade Barrientos
 
PPTX
Data Structure Searching.pptx
SourabhTaneja4
 
PPTX
Data calculatio. Algorithms by Charlotte.pptx
ManishBaranwal10
 
PPTX
Sorting in python
Simplilearn
 
PPTX
2.4 Lecture.pptx
TDeutsch1
 
day 13.pptx
codewavecommunity44
 
Python programming Sequence Datatypes -Tuples
BushraKm2
 
Sorting Algorithms to arrange data in particular format
itsusamazahid
 
1.4 Sorting.pptx
Sujan527908
 
Lecture 13 data structures and algorithms
Aakash deep Singhal
 
Unit III Version I.pptx
ssuserd602fd
 
Part 2 - Python Tutorial | Introduction to Lists
Shivam Mitra
 
Chapter 5 searching and sorting handouts with notes
mailund
 
SORTING techniques.pptx
Dr.Shweta
 
Python - Lecture 10
Ravi Kiran Khareedi
 
DSA_chapter and chapter 3 _03_Sorting Algorithms.pptx
tahliildhoore54
 
Sorting method data structure
sunilchute1
 
Sorting algorithm
Muhammad Farhan
 
Python programing basic knowledge hh.pdf
raviofficialmrm06
 
L 14-ct1120
Zia Ush Shamszaman
 
Data Structures and Algorithms
Mark Jade Barrientos
 
Data Structure Searching.pptx
SourabhTaneja4
 
Data calculatio. Algorithms by Charlotte.pptx
ManishBaranwal10
 
Sorting in python
Simplilearn
 
2.4 Lecture.pptx
TDeutsch1
 
Ad

More from IHTMINSTITUTE (16)

PPTX
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
PPTX
Python PCEP Creating Simple Functions
IHTMINSTITUTE
 
PPTX
Python PCEP Function Parameters
IHTMINSTITUTE
 
PPTX
Python PCEP Functions
IHTMINSTITUTE
 
PPTX
Python PCEP Multidemensional Arrays
IHTMINSTITUTE
 
PPTX
Python PCEP Operations On Lists
IHTMINSTITUTE
 
PPTX
Python PCEP Logic Bit Operations
IHTMINSTITUTE
 
PPTX
Python PCEP Loops
IHTMINSTITUTE
 
PPTX
Python PCEP Comparison Operators And Conditional Execution
IHTMINSTITUTE
 
PPTX
Python PCEP How To Talk To Computer
IHTMINSTITUTE
 
PPTX
Python PCEP Variables
IHTMINSTITUTE
 
PPTX
Python PCEP Operators
IHTMINSTITUTE
 
PPTX
Python PCEP Literals
IHTMINSTITUTE
 
PPTX
IHTM Python PCEP Hello World
IHTMINSTITUTE
 
PPTX
IHTM Python PCEP Introduction to Python
IHTMINSTITUTE
 
PPTX
Python PCEP Welcome Opening
IHTMINSTITUTE
 
Python PCEP Tuples and Dictionaries
IHTMINSTITUTE
 
Python PCEP Creating Simple Functions
IHTMINSTITUTE
 
Python PCEP Function Parameters
IHTMINSTITUTE
 
Python PCEP Functions
IHTMINSTITUTE
 
Python PCEP Multidemensional Arrays
IHTMINSTITUTE
 
Python PCEP Operations On Lists
IHTMINSTITUTE
 
Python PCEP Logic Bit Operations
IHTMINSTITUTE
 
Python PCEP Loops
IHTMINSTITUTE
 
Python PCEP Comparison Operators And Conditional Execution
IHTMINSTITUTE
 
Python PCEP How To Talk To Computer
IHTMINSTITUTE
 
Python PCEP Variables
IHTMINSTITUTE
 
Python PCEP Operators
IHTMINSTITUTE
 
Python PCEP Literals
IHTMINSTITUTE
 
IHTM Python PCEP Hello World
IHTMINSTITUTE
 
IHTM Python PCEP Introduction to Python
IHTMINSTITUTE
 
Python PCEP Welcome Opening
IHTMINSTITUTE
 
Ad

Recently uploaded (20)

PDF
Slides: Eco Economic Epochs for The World Game (s) pdf
Steven McGee
 
PDF
B M Mostofa Kamal Al-Azad [Document & Localization Expert]
Mostofa Kamal Al-Azad
 
PDF
Global Networking Trends, presented at the India ISP Conclave 2025
APNIC
 
PDF
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
PPTX
Pitch PitchPitchPitchPitchPitchPitch.pptx
157551
 
PPTX
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
taqyed
 
PPT
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
PPTX
最新版加拿大奎斯特大学毕业证(QUC毕业证书)原版定制
taqyed
 
PPTX
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
PPTX
BitRecover OST to PST Converter Software
antoniogosling01
 
PDF
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
PDF
Logging and Automated Alerting Webinar.pdf
ControlCase
 
PDF
DDoS in India, presented at INNOG 8 by Dave Phelan
APNIC
 
PPTX
BASICS OF SAP _ ALL ABOUT SAP _WHY SAP OVER ANY OTHER ERP SYSTEM
AhmadAli716831
 
PPTX
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
PPTX
Azure_Landing_Zone_Best_Practices_Visuals.pptx
fredsonbarbosa1
 
PPTX
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
AhmadAli716831
 
PPTX
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
PPTX
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
PDF
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 
Slides: Eco Economic Epochs for The World Game (s) pdf
Steven McGee
 
B M Mostofa Kamal Al-Azad [Document & Localization Expert]
Mostofa Kamal Al-Azad
 
Global Networking Trends, presented at the India ISP Conclave 2025
APNIC
 
ChatGPT A.I. Powered Chatbot and Popularization.pdf
StanleySamson1
 
Pitch PitchPitchPitchPitchPitchPitch.pptx
157551
 
原版澳洲斯文本科技大学毕业证(SUT毕业证书)如何办理
taqyed
 
Almos Entirely Correct Mixing with Apps to Voting
gapati2964
 
最新版加拿大奎斯特大学毕业证(QUC毕业证书)原版定制
taqyed
 
IAREUOUSTPIDWHY$)CHARACTERARERWUEEJJSKWNSND
notgachabite123
 
BitRecover OST to PST Converter Software
antoniogosling01
 
Clive Dickens RedTech Public Copy - Collaborate or Die
Clive Dickens
 
Logging and Automated Alerting Webinar.pdf
ControlCase
 
DDoS in India, presented at INNOG 8 by Dave Phelan
APNIC
 
BASICS OF SAP _ ALL ABOUT SAP _WHY SAP OVER ANY OTHER ERP SYSTEM
AhmadAli716831
 
原版一样(ISM毕业证书)德国多特蒙德国际管理学院毕业证多少钱
taqyed
 
Azure_Landing_Zone_Best_Practices_Visuals.pptx
fredsonbarbosa1
 
PROCESS FOR CREATION OF BUSINESS PARTNER IN SAP
AhmadAli716831
 
原版一样(ANU毕业证书)澳洲澳大利亚国立大学毕业证在线购买
Taqyea
 
ChatGPT_and_Its_Uses_Presentationss.pptx
Neha Prakash
 
BroadLink Cloud Service introduction.pdf
DevendraDwivdi1
 

Python PCEP Sorting Simple Lists

  • 1. Module 2 Data Collections – Lists, Tuples, and Dictionaries Sorting simple lists
  • 2. Module 2 Sorting simple lists Bubble sort 8 10 6 2 4 8 6 10 2 4 8 6 2 10 4 8 6 2 4 10 6 8 2 4 10 6 2 8 4 10 6 2 4 8 10 2 6 4 8 10 2 4 6 8 10 Increasing order
  • 3. Module 2 Sorting simple lists Sorting a list my_list = [8, 10, 6, 2, 4] # list to sort swapped = True # It's a little fake, we need it to enter the while loop. while swapped: swapped = False # no swaps so far for i in range(len(my_list) - 1): if my_list[i] > my_list[i + 1]: swapped = True # a swap occurred! my_list[i], my_list[i + 1] = my_list[i + 1], my_list[i] print(my_list)
  • 4. Module 2 Sorting simple lists Ready-to-use tools Python has its own sorting mechanisms: .sort() my_list = [8, 10, 6, 2, 4] # list to sort swapped = True # It's a little fake, we need it to enter the while loop. my_list.sort() print(my_list)
  • 5. Module 2 Sorting simple lists Key takeaways sort() •to sort elements of a list reverse() •to reverse the list