From the course: Advanced Python
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Sequences - Python Tutorial
From the course: Advanced Python
Solution: Sequences
- [Narrator] For this challenge, we needed to process a string and then return a set of unique punctuation characters in the string. So, my solution uses a set comprehension to do this because it's going to build a set out of each of the characters in the string. And I also use the string.punctuation constant that we learned about in the chapter on string processing. To do this, I simply need to write my comprehension, which checks to see if each character in the given sentence is in the string.punctuation sequence and if it is, then it is added to the results set. So, once I have the complete set, I can return the result. Using a set comprehension automatically removes duplicates from the result so I don't have to do any additional processing. So, let's go ahead and click on the "Test my code." And we can see that for this particular test, we have the comma, colon, exclamation point, and period. And sure enough, that's exactly what we get here in the result. Let's try a different…