My code finds 46 words in words.txt but your code finds 4 words. Why is it like that?
Here's my code:
def is_three_consecutive_double(word):
"""Tests if a word contains three consecutive double letters
Args:
word (str): ASCII letters
Returns:
bool: True or False
"""
c = 0
while len(word) > 1:
if word[0] == word[1]:
c += 1
word = word[1:]
return True if c == 3 else False
def main():
"""Reads words.txt with English words
Prints a word list and count
"""
f = open('words.txt')
words_list = f.read().split('\n')
words_list.remove('')
f.close()
consecutive_double = []
count = 0
for word in words_list:
if is_three_consecutive_double(word):
consecutive_double.append(word)
count += 1
print(consecutive_double, count)
if __name__ == '__main__':
main()
My code finds 46 words in words.txt but your code finds 4 words. Why is it like that? Here's my code:
I use VS code 1.55.0 on Windows 10. Thanks