Hey guys, wondering if you can help with this as I am stuck on step 3. First I have a question about step two though.
For step two: the .strip() function doesn’t work on the email file, but the .replace() function does. However if I save email_one as a string rather than a .txt file, then the .strip() function will work. Can anyone explain why that is?
So for example, this works:
email_split = email.replace("learning algorithms", "*" * len("learning algorithms")) return email_split
but this doesn’t
email_split = email.strip("learning algorithms") return email_split
I don’t get why…
Now on to my main question. For step three, my “for” loop is only returning the last value, rather than iterating through the list.
def proprietary_terms(email): proprietary_terms = ["she", "personality matrix", "sense of self", "self-preservation", "learning algorithms", "her", "herself"] for i in proprietary_terms: if i in email: email_propterm = email.replace(i, "*" * len(i)) return email_propterm #print(email_two) print(proprietary_terms(email_two))
So when I call the function the only word that gets replaced with “*” * len(i) is “herself”. I cant figure out why thats happening. When I indent it (as expected) it only iterates through the first value of i, usually when that happens I unindent and it iterates through the whole list, but not this time.
Any help would be greatly appreciated. Thanks.