15
Last seen 5 years ago
Member for 9 years, 3 months, 23 days
Difficulty Normal
The quantifiers (plus signs) in your regex are superfluous. There is no need to match more than one character of each of the character classes.
More
if foo == bar:
return True
else:
return False
can be written more concisely as:
return foo == bar
More
I expect there to be performance penalties at least for:
* lowercasing words that are already lower case (by precondition)
* compiling and evaluating regular expressions for simple substring matches
* branching to an empty else statement
In summary, this solution does not look particularly speed-o
More
The text is lowercased for each word in the words set.
It should be faster to do this only once.
More
This is a bit scary in that the loop might never terminate or the fibo list might have a typo. Mission accomplished.
More
You might want to remove the debug output and the boilerplate comment (replace this...).
More
A set of words is iterable. There is no need to transform it to a list first.
Neither do we need to use an index i since we don't care about it in the loop.
Your solution can thus be simplified like this:
def count_words(text, words):
N = 0
text = text.lower()
for
More