I’ll definitely put into practice your thoughts on cosmetics. I can see the benefits in simplifying things.
def isalpha(value): return value.isalpha()
str.isalpha evaluates to a boolean, so there’s no point in me using an if else block to return
I removed checks for
"'"because I want to censor things like
"she"in the word
No it isn’t. I think all I accomplished there was showing that the function needs work.
I overthought my last isalpha function, and was trying to make sure it could work for strings and characters so that I could use it to filter.
But I now realise that I can just join each element in result, save that to a new variable, then iterate over the elements in the variable using the isalpha function in its current form:
joined_elements = ["".join(element) for element in groupby(isalpha, test_string)] alpha = [element for element in joined_elements if isalpha(element)] non_alpha = [element for element in joined_elements if not isalpha(element)]
Having had another look at your
groupby5 function, I better understand how to add to
current unconditionally, as you mentioned before.
This is more for my understanding: The function starts with nothing in
current, but after one iteration, it contains a character we can compare future characters with. Plus, nothing was appended to
current was empty on the first iteration.
Which is what your first if block is doing.
I’ll have a go at getting the indexes of phrases I want to censor, then censoring the phrase.
I’ll keep in mind your
I attempted getting indexes using this, but didn’t have much success:
indexes =  bad_words = ["she", "processing power"] for word in bad_words: alpha_repeat = [alpha[i : i + 1 + word.count(" ")] for i in range(len(alpha))] for element in alpha_repeat: index = 0 if word.split() == element: for word in element: indexes.append(alpha_repeat.index(element) + index) index += 1 print(indexes) # [17, 17, 17, 17, 17, 28, 29]
One obvious problem is my use of str.index. Another one is probably the amount of nesting I’m doing.