Save this video free

Python (Fall 2026) Module 9-5: Algorithms and Solving A8 Part 2

Bill Moseley, Ph.D. - Computer Science Educator · 8:03 · Watch on YouTube

Part of Bakersfield College COMP B10. See all 47 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Bill Moseley refactors email-address cleanup in Python by creating a reusable `cleanHalf` function that keeps alphanumeric characters plus periods, hyphens, and underscores, stopping at the first invalid character. He applies it to both halves of an address, restores the reversed first half, joins the halves with `@`, and returns the cleaned string from `cleanEmail`.

Key takeaways

Chapters

0:00 Build `cleanHalf` to Filter Email-Address Characters
4:00 Clean Both Halves and Restore the Reversed First Half
6:30 Reassemble and Return the Cleaned Email Address

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 So that's what I want there. So the first half  is reversed. Second half is not reversed. Now I'm going to do the same thing to this that  I am to this. Anytime you say I'm going to do the same thing more than one time, your brain  should immediately go to, I'm going to create a function so I don't have to type the same code  twice. So, I'm going to create another function that's going to be called from cleanEmail. And I'm  going to create it up here, and it's going to be called cleanHalf. The idea is that it's going to,  this function is going to be in charge of doing this work. For each letter, check and see if it's  valid, and if it is, add it to a return string. If it's not, break the loop and return. Okay. So what  I'm going to do is I'm going to take that half,

0:56 str, as a string, and I'm going to say strClean,  cleanHalf, ch. Remember, these variables live only inside the function. What happens in the  function stays in the function. So it doesn't matter what I call them, really, because they  only live inside that function. So I'm going to start out with empty string. Remember when  I cleaned out that Bakersfield College string? I threw away all the punctuation, kept the words.  We're going to do the same thing here. I'm going to say for strLetter in str. So for each letter in  the half, we're going to say is, or if strLetter is numeric,

1:52 or strLetter in, if there's an str, if, if  it's in this string. So, I have a hyphen, underscore, period, and that's really it,  right? Because I'm looking back at this, this one. There won't be an at sign. If  there's another at sign in my, in my,

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.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.