Combining Lists andStrings
in Python
Let's play with words and data using Python's lists and strings!
by Rohit Pimpale
2.
What Are Listsand Strings?
List
A collection of items in order, like your playlist songs.
String
Text inside quotes, like a sentence or a secret message.
3.
Why Combine Listsand
Strings?
1 Turn a sentence into a list of words for processing.
2 Create secret codes by shifting letters around.
3 Count how often words appear in stories.
4 Think: Which games use lists or word data?
4.
Activity 1 –Split a Sentence
Goal
Turn a sentence into a list of words using split().
Outcome
Learn how strings can become lists for easy use.
5.
Activity 2 –Join a List into a
Sentence
Goal
Use join() to combine list items into a string sentence.
Application
Make simple secret codes by shifting letters in words.
6.
Activity 3 –Secret Message
Encoder
Create a Caesar Cipher
Shift letters to encode messages securely.
Use Lists and Strings
Convert text to lists, shift characters, join back.
Practice Coding
Build your own encoder step-by-step.
7.
Real-World AI Applications
Chatbots:Turn messages into word lists for understanding.
Games: Check if words exist, like in Scrabble.
Social Media: Count hashtags and emojis in posts.
How might social apps count your hashtags and emojis?
8.
Let's Build aWord Counter!
Goal
Count how often each word appears in a sentence.
Why
Useful for text analysis and data insights.
9.
Group Discussion
1. Howcan lists and strings help build simple games?
2. What happens when commas are missing in a list?
3. Why are lists and strings important for AI robots?
10.
Summary & Homework
KeyTakeaways
• Lists hold collections; strings hold text.
• Split sentences or join words easily.
• Great for games, codes, and AI tasks.
Homework
1. Create a program to count letters in words from a sentence.
2. Bonus: Build a secret code decoder!