SlideShare a Scribd company logo
1 of 26
Python with AI – Lists
Lists in python
• A list holds ordered collection of items.
• And item can be a string or a number
Lists in python
• A list holds ordered collection of items.
• And item can be a string or a number
Lists in python
• A list holds ordered collection of items.
• And item can be a string or a number
Lists in python
• A list holds ordered collection of items.
• And item can be a string or a number
Vs
Add an item to a list
• A list holds ordered collection of items.
• And item can be a string or a number
Access an item and delete
• A list holds ordered collection of items.
• And item can be a string or a number
Lists inside lists
• An item inside a list can be another list
Exercise
• An item inside a list can be another list
• How can you access the item mouse?
Exercise
• An item inside a list can be another list
• How can you access and print the item mouse
• How can you access and print the item [‘a’] ?
Exercise
• An item inside a list can be another list
• How can you access and print the item mouse
• How can you access and print the item [‘a’] ?
• How can you access and print a?
Exercise
• An item inside a list can be another list
• How can you access and print the item mouse
• How can you access and print the item [‘a’] ?
• How can you access and print a?
Add two lists
• Just like strings, you can add lists
• This can be done in several ways
• Create a 3rd list that is a combination of the first two lists
Add two lists
• Just like strings, you can add lists
• This can be done in several ways
• Create a 3rd list that is a combination of the first two lists
Add two lists
• Just like strings, you can add lists
• This can be done in several ways
• Create a 3rd list that is a combination of the first two lists
• Append or extend to an existing list
What’s the difference between the two?
Try them and print your responses
Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
Flowchart with lists and loops
Start
Declare list_sample [4, 3, 2, 5, 8]
Declare a variable len_list that stored the length of the list
Flowchart with lists and loops
Start
Declare list_sample [4, 3, 2, 5, 8]
Declare a variable len_list that stored the length of the list
Flowchart with lists and loops
Start
Declare list_sample [4, 3, 2, 5, 8]
Declare a number a=0
Declare a variable len_list that stores the length of the list
If a <
len_list
Stop a = a+1
value =
list_sample[a]
If value is
a even
number
Print value
TrueFalse
False True
Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
Flowchart with lists and loops
• Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
Declare a number a=0
If a >
len_list
Stop a = a+1
value =
list_sample[a]
If value is
a even
number
Print value
True False
False True
Exercise: Design a chat bot - flowchart
• list_happy_words = [“joyful”, “happy”, “amazing”, “beautiful”]
• list_sad_words = [“sad”, “tears”, “crying”, “depressed”]
• list_games = [“tetris”, “flappy bird”, “snake”]
• Ask the user to enter a word that describes their feeling
• If the feeling they enter is one of the list_happy_words, print “Glad you are
happy” and exit.
• If the feeling they enter is one of the list_sad_words, ask the user to play
one of the games from the list list_games.
• Ask the user again how they are feeling and continue till the list of games is
exhausted.
• If you already suggested all the games and the user is still unhappy, exit.
Exercise: Design a chat bot - code
Start
Declare the 3 lists
Ask the user to input a word describing their feeling, save the string
Check if
word is a
part of
happy list
Check if
word is a
part of
sad list
True
Stop
Print
sentence
False
False True
Print
sentence
Print
game
Exercise: Design a chat bot - code
Start
Declare the 3 lists
Ask the user to input a word describing their feeling, save the string
Check if
word is a
part of
happy list
Check if
word is a
part of
sad list
True
Stop
Print
sentence
False
False True
Print
sentence
Print
game
Check if
your
games
list is
over
False
Lets try it!
http://aiclub.world

More Related Content

Similar to PA1 lists

powerpoint 2-13.pptx
powerpoint 2-13.pptxpowerpoint 2-13.pptx
powerpoint 2-13.pptxJuanPicasso7
 
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...KavineshKumarS
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology InitiativeBasil Bibi
 
ProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdf
ProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdfProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdf
ProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdflailoesakhan
 
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdfProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdflailoesakhan
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptxdeivanayagamramachan
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonchanna basava
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptxASRPANDEY
 
Brixton Library Technology Initiative
Brixton Library Technology InitiativeBrixton Library Technology Initiative
Brixton Library Technology InitiativeBasil Bibi
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsBlue Elephant Consulting
 
Javascript ADT - List
Javascript   ADT - ListJavascript   ADT - List
Javascript ADT - ListSamuel Santos
 

Similar to PA1 lists (20)

Pa1 lists subset
Pa1 lists subsetPa1 lists subset
Pa1 lists subset
 
Pa1 flow chart
Pa1 flow chartPa1 flow chart
Pa1 flow chart
 
LIST_tuple.pptx
LIST_tuple.pptxLIST_tuple.pptx
LIST_tuple.pptx
 
powerpoint 2-13.pptx
powerpoint 2-13.pptxpowerpoint 2-13.pptx
powerpoint 2-13.pptx
 
tupple.pptx
tupple.pptxtupple.pptx
tupple.pptx
 
Lists in Python
Lists in PythonLists in Python
Lists in Python
 
Intro to Lists
Intro to ListsIntro to Lists
Intro to Lists
 
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Python Lists is a a evry jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
Brixon Library Technology Initiative
Brixon Library Technology InitiativeBrixon Library Technology Initiative
Brixon Library Technology Initiative
 
ProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdf
ProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdfProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdf
ProgFund_Lecture_3_Data_Structures_and_Iteration-1.pdf
 
Baabtra.com little coder chapter - 3
Baabtra.com little coder   chapter - 3Baabtra.com little coder   chapter - 3
Baabtra.com little coder chapter - 3
 
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdfProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
ProgPrinc_Lecture_3_Data_Structures_and_Iteration-2.pdf
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Lists python.pptx
Lists python.pptxLists python.pptx
Lists python.pptx
 
Brixton Library Technology Initiative
Brixton Library Technology InitiativeBrixton Library Technology Initiative
Brixton Library Technology Initiative
 
An Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List AlgorithmsAn Introduction To Python - Tables, List Algorithms
An Introduction To Python - Tables, List Algorithms
 
Javascript ADT - List
Javascript   ADT - ListJavascript   ADT - List
Javascript ADT - List
 

More from aiclub_slides

Linear regression middleschool
Linear regression middleschoolLinear regression middleschool
Linear regression middleschoolaiclub_slides
 
Pa2 project template
Pa2 project templatePa2 project template
Pa2 project templateaiclub_slides
 
Knn intro advanced_middleschool
Knn intro advanced_middleschoolKnn intro advanced_middleschool
Knn intro advanced_middleschoolaiclub_slides
 
M1 regression metrics_middleschool
M1 regression metrics_middleschoolM1 regression metrics_middleschool
M1 regression metrics_middleschoolaiclub_slides
 
Ai in real life face detection
Ai in real life   face detectionAi in real life   face detection
Ai in real life face detectionaiclub_slides
 
Res net high level intro
Res net high level introRes net high level intro
Res net high level introaiclub_slides
 
Neural networks and flattened images
Neural networks and flattened imagesNeural networks and flattened images
Neural networks and flattened imagesaiclub_slides
 
What is a_neural_network
What is a_neural_networkWhat is a_neural_network
What is a_neural_networkaiclub_slides
 
How neural networks learn part iii
How neural networks learn part iiiHow neural networks learn part iii
How neural networks learn part iiiaiclub_slides
 
Introduction to deep learning image classification
Introduction to deep learning   image classificationIntroduction to deep learning   image classification
Introduction to deep learning image classificationaiclub_slides
 
Accuracy middleschool
Accuracy middleschoolAccuracy middleschool
Accuracy middleschoolaiclub_slides
 
Introduction to classification_middleschool
Introduction to classification_middleschoolIntroduction to classification_middleschool
Introduction to classification_middleschoolaiclub_slides
 
Introduction to the cloud
Introduction to the cloudIntroduction to the cloud
Introduction to the cloudaiclub_slides
 
Ai lifecycle and navigator
Ai lifecycle and navigatorAi lifecycle and navigator
Ai lifecycle and navigatoraiclub_slides
 

More from aiclub_slides (20)

Linear regression middleschool
Linear regression middleschoolLinear regression middleschool
Linear regression middleschool
 
Pa2 project template
Pa2 project templatePa2 project template
Pa2 project template
 
Knn intro advanced_middleschool
Knn intro advanced_middleschoolKnn intro advanced_middleschool
Knn intro advanced_middleschool
 
M1 regression metrics_middleschool
M1 regression metrics_middleschoolM1 regression metrics_middleschool
M1 regression metrics_middleschool
 
Pa1 json requests
Pa1 json requestsPa1 json requests
Pa1 json requests
 
Mnist images
Mnist imagesMnist images
Mnist images
 
Mnist images
Mnist imagesMnist images
Mnist images
 
Ai in real life face detection
Ai in real life   face detectionAi in real life   face detection
Ai in real life face detection
 
Cnn
CnnCnn
Cnn
 
Res net high level intro
Res net high level introRes net high level intro
Res net high level intro
 
Neural networks and flattened images
Neural networks and flattened imagesNeural networks and flattened images
Neural networks and flattened images
 
What is a_neural_network
What is a_neural_networkWhat is a_neural_network
What is a_neural_network
 
How neural networks learn part iii
How neural networks learn part iiiHow neural networks learn part iii
How neural networks learn part iii
 
Introduction to deep learning image classification
Introduction to deep learning   image classificationIntroduction to deep learning   image classification
Introduction to deep learning image classification
 
Accuracy middleschool
Accuracy middleschoolAccuracy middleschool
Accuracy middleschool
 
Introduction to classification_middleschool
Introduction to classification_middleschoolIntroduction to classification_middleschool
Introduction to classification_middleschool
 
Introduction to the cloud
Introduction to the cloudIntroduction to the cloud
Introduction to the cloud
 
Basics of data
Basics of dataBasics of data
Basics of data
 
Ai basics
Ai basicsAi basics
Ai basics
 
Ai lifecycle and navigator
Ai lifecycle and navigatorAi lifecycle and navigator
Ai lifecycle and navigator
 

Recently uploaded

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

PA1 lists

  • 1. Python with AI – Lists
  • 2. Lists in python • A list holds ordered collection of items. • And item can be a string or a number
  • 3. Lists in python • A list holds ordered collection of items. • And item can be a string or a number
  • 4. Lists in python • A list holds ordered collection of items. • And item can be a string or a number
  • 5. Lists in python • A list holds ordered collection of items. • And item can be a string or a number Vs
  • 6. Add an item to a list • A list holds ordered collection of items. • And item can be a string or a number
  • 7. Access an item and delete • A list holds ordered collection of items. • And item can be a string or a number
  • 8. Lists inside lists • An item inside a list can be another list
  • 9. Exercise • An item inside a list can be another list • How can you access the item mouse?
  • 10. Exercise • An item inside a list can be another list • How can you access and print the item mouse • How can you access and print the item [‘a’] ?
  • 11. Exercise • An item inside a list can be another list • How can you access and print the item mouse • How can you access and print the item [‘a’] ? • How can you access and print a?
  • 12. Exercise • An item inside a list can be another list • How can you access and print the item mouse • How can you access and print the item [‘a’] ? • How can you access and print a?
  • 13. Add two lists • Just like strings, you can add lists • This can be done in several ways • Create a 3rd list that is a combination of the first two lists
  • 14. Add two lists • Just like strings, you can add lists • This can be done in several ways • Create a 3rd list that is a combination of the first two lists
  • 15. Add two lists • Just like strings, you can add lists • This can be done in several ways • Create a 3rd list that is a combination of the first two lists • Append or extend to an existing list What’s the difference between the two? Try them and print your responses
  • 16. Flowchart with lists and loops • Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
  • 17. Flowchart with lists and loops Start Declare list_sample [4, 3, 2, 5, 8] Declare a variable len_list that stored the length of the list
  • 18. Flowchart with lists and loops Start Declare list_sample [4, 3, 2, 5, 8] Declare a variable len_list that stored the length of the list
  • 19. Flowchart with lists and loops Start Declare list_sample [4, 3, 2, 5, 8] Declare a number a=0 Declare a variable len_list that stores the length of the list If a < len_list Stop a = a+1 value = list_sample[a] If value is a even number Print value TrueFalse False True
  • 20. Flowchart with lists and loops • Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
  • 21. Flowchart with lists and loops • Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers
  • 22. Flowchart with lists and loops • Given a list list_sample = [4, 3, 2, 5, 8], print all the even numbers Declare a number a=0 If a > len_list Stop a = a+1 value = list_sample[a] If value is a even number Print value True False False True
  • 23. Exercise: Design a chat bot - flowchart • list_happy_words = [“joyful”, “happy”, “amazing”, “beautiful”] • list_sad_words = [“sad”, “tears”, “crying”, “depressed”] • list_games = [“tetris”, “flappy bird”, “snake”] • Ask the user to enter a word that describes their feeling • If the feeling they enter is one of the list_happy_words, print “Glad you are happy” and exit. • If the feeling they enter is one of the list_sad_words, ask the user to play one of the games from the list list_games. • Ask the user again how they are feeling and continue till the list of games is exhausted. • If you already suggested all the games and the user is still unhappy, exit.
  • 24. Exercise: Design a chat bot - code Start Declare the 3 lists Ask the user to input a word describing their feeling, save the string Check if word is a part of happy list Check if word is a part of sad list True Stop Print sentence False False True Print sentence Print game
  • 25. Exercise: Design a chat bot - code Start Declare the 3 lists Ask the user to input a word describing their feeling, save the string Check if word is a part of happy list Check if word is a part of sad list True Stop Print sentence False False True Print sentence Print game Check if your games list is over False