Python (Fall 2026) Module 8-7: A8 Explanation
Overview
Bill Moseley explains the A8 email-extractor assignment by showing how to find candidate addresses in text and remove punctuation with Python string operations. He outlines three functions (extract emails, remove duplicates, and check list membership) and demonstrates how to test and troubleshoot them using the Abraham Lincoln and Taylor Swift starter text.
Key takeaways
- Python's str.find('@') returns the position of an at sign when present and -1 when absent, making it a straightforward way to identify candidate email words.
- String splitting can isolate candidate addresses, but punctuation attached to the word must be cleaned before returning results.
- Checking the last character with strWord[-1] and slicing the string provides one method for removing a sentence-ending period.
- The A8 extractor should return a list from a text-string input; the assignment also includes duplicate removal and list-membership checking.
- Testing against both Lincoln and Taylor Swift starter strings exposes edge cases, especially candidates with punctuation mixed into their beginning or end.
Chapters
- Moseley identifies the @ sign as the first clue when searching web-page text for email addresses.
- Candidate addresses need text before and after @, a domain containing at least one period, and no trailing period.
- The examples distinguish email punctuation from sentence punctuation, such as the period after [email protected].
- Split a text string into words, then use strWord.find('@') to identify words containing an at sign; find returns -1 when it finds no match.
- Use strWord[-1] to inspect the last character and string slicing to remove a trailing period.
- Moseley also demonstrates reversing a string to inspect and slice its first character, emphasizing practice with string indexing and slicing.
- The A8 starter materials include Lincoln and Taylor Swift text plus an A8 template containing two strings with embedded email addresses.
- The extractor should take a string, split it into words, find @ signs, clean surrounding punctuation, and return a list of email candidates.
- The assignment also calls for removing duplicates by converting a list to a set and back, and checking whether an email appears in a list.
- Moseley debugs the extractor by replacing temporary print statements with list appends; remaining challenge cases include illegal punctuation at the start or end of a candidate.
Transcript excerpt
0:01 So that's sort of your warm-up, right? I'm giving you some ideas. A8 takes that a little bit further. And what I'm going to give you is called the email extractor. Now, this is an actual and very unfortunate real world scenario, right? This is how we end up on all of those terrible spam lists out there in the world. Because what we have are programs like this that go out there, look at a web page, and they, they grab all of the email addresses from that web page and put them into a database. And then those databases get sold to people who want to send you ads for, you know, free prescription medicine that I won't name the specifics of, and things like that. So,
1:00 yeah, you know what I'm talking about. So, the, this is actually a real world application of this text processing that is very, very common and pretty useful. But for those, that list of email addresses to be valid, right, they have to be real email addresses that have certain characteristics. Now, if I write an email address on the board, and I, I don't have a pen here, unfortunately, but if I were to write an email address on the board versus another piece of text, how would you know that the thing I'm showing you is an email address? That sign, right? That's the, that's the big giveaway. That's pretty bright. I'm not sure that'll show up. Thank you, though. I appreciate it. I think I'm, I'm going to just use my
1:56 amazing ability to write text up here. So, if I say Bill Moseley bakersfield college.edu, do we all agree that that's an email address? Okay. That has an at sign. Is that an email address? How do you know?
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.