Python (Fall 2026) Module 9-4: Algorithms and Solving A8 Part 1
Overview
Bill Moseley explains why Assignment 8’s email extractor is an algorithmic challenge: a candidate must satisfy multiple structural and character rules, not merely contain an @ sign. He breaks the task into stages (identify likely candidates, split each candidate at @, reverse the first half to scan outward from the boundary, and keep only legal characters) then begins implementing the approach with Python’s `split()` and `[::-1]`.
Key takeaways
- A reliable email extractor must apply several independent rules: an @ sign with text on both sides, a period after @, and at least two characters following that period.
- Splitting a candidate at @ separates the address into local-part and domain-side strings, making their cleanup easier to reason about.
- Reversing the first half with Python’s `[::-1]` lets the program scan from the @ boundary toward the beginning, stopping at the first illegal character.
- The starter `findEmails` function identifies only probable candidates by searching space-separated words for @; it does not yet validate or clean them.
- `cleanEmail` is designed as a separate function that accepts one suspected address and returns a cleaned string, keeping candidate discovery distinct from cleanup.
Chapters
- Assignment 8 requires an @ sign with text on both sides, at least one period after @, and at least two characters after that period.
- Valid addresses cannot start or end with punctuation, contain spaces, or place a period at the beginning, end, or next to @.
- Moseley proposes splitting at @ and scanning each half outward from the boundary, stopping when a character is not allowed.
- The existing `findEmails` function splits input text on spaces into `liText` and collects words containing @ as probable email addresses.
- The candidate list can include extra surrounding characters, so `cleanEmail` is introduced to process one suspected address at a time.
- The cleanup plan is to divide each candidate into two halves and remove invalid characters from the outer ends.
- `strEmail.split('@')` creates a two-item `liEmail` list, with the first half at index 0 and the second half at index 1.
- The code assigns those list elements to separate strings so each side of the address can be cleaned independently.
- Python slice notation `[::-1]` reverses the first half, positioning its outer characters for a character-by-character scan from the @ boundary.
Transcript excerpt
0:02 So, I want to go back. I want to circle back to assignment eight and talk a little bit about algorithmic thinking as it relates to assignment 8. You remember the email extractor, of course. That's probably what many of you are working on right now. At least according to the number of assignments that I've seen turned in, a lot of people are still working on this, and that's normal. But the reason the email extractor can be difficult is because it's a fairly complex program, right? We've got all of these rules for an email. It has to have an at sign before and after with text before and after. Has to have at least one period after the at sign. It has to have at least two characters after the period after the at sign. It can't start or end with punctuation. And it can include the following characters in addition to alphanumeric characters. It can't
0:59 include spaces. And it can't have a period at the beginning or end or next to the at sign. So those are all rules that we have to figure out. If we want to validate and extract email addresses, we have to translate those rules to functions in our code that deal with those things. So, it's become an, a complex algorithm for something that seems pretty simple at first, because we can recognize the email address here. We have an algorithm internally that allows us to easily recognize where the email address is and where there are characters that don't belong here. So, the key is trying to figure out, what are the steps our brain is going through to do that. So, we talked about this last time. One of the first things we do is we look for an at sign and we
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.