

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 8
click for more info
Not enough gems
Cost: 6 gems
1: Lists
incomplete
2: Lists Continued
incomplete
3: Counting in Programming
incomplete
4: Indexing Into Lists
incomplete
5: List Length
incomplete
6: List Updates
incomplete
7: Appending in Python
incomplete
8: Pop Values
incomplete
9: Counting the Items in a List
incomplete
10: No-Index Syntax
incomplete
11: Find an Item in a List
incomplete
12: Find the Increase
incomplete
13: Find Max
incomplete
14: Modulo Operator in Python
incomplete
15: Slicing Lists
incomplete
16: List Operations – Concatenate
incomplete
17: List Operations – Contains
incomplete
18: List Deletion
incomplete
19: Tuples
incomplete
20: First Element
incomplete
21: Reverse List
incomplete
22: Filter Messages
incomplete
23: Even Teams
incomplete
24: Alchemy Ingredients
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
You're about to write a bit more code in a single function than you have before.
Do not try to write it all at once. Start with the outermost loop and work your way inward. Add extra print() statements and run your code often to make sure it's doing what you expect. Just make sure to remove the extra print() statements before submitting your code.
Running your code often to make sure each line is doing what you expect is called "debugging." All programmers, even seasoned professionals, break large problems down into small ones that they can debug line by line.
Because we're working with strings that need to be converted to lists and vice versa, here are a couple helpful Python methods we can use to make our lives much easier.
The .split() method in Python is called on a string and returns a list by splitting the string based on a given delimiter. If no delimiter is provided, it will split the string on whitespace. Here's a quick example:
message = "hello there sam"
words = message.split()
print(words)
# Prints: ["hello", "there", "sam"]
The .join() method is called on a delimiter (what goes between all the words in the list), and takes a list of strings as input.
list_of_words = ["hello", "there", "sam"]
sentence = " ".join(list_of_words)
print(sentence)
# Prints: "hello there sam"
We need to filter the profanity out of our game's live chat feature! Complete the filter_messages function. It takes a list of chat messages as input and returns two new lists:
dang removed.dang words that were removed from each message at that particular index.Here are some examples:
messages = ["dang it bobby!", "look at it go"]
filter_messages(messages) # returns ["it bobby!", "look at it go"], [1, 0]
messages2 = [
"That's the bloody dang Reaper of Mars...",
"Pax au Telemanus!",
"I was never taught how to use a dang razor!",
]
filter_messages(
messages2
) # returns ["That's the bloody Reaper of Mars...", "Pax au Telemanus!", "I was never taught how to use a razor!"], [1, 0, 1]
Here are the steps for you to follow. There are a LOT of steps! It won't be easy, but if you follow the steps exactly, you will pass this assignment: