Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active Jun 5, 2021
Embed
What would you like to do?
Python / Language / Strings
# Get the words with three consecutive double letters
# https://github.com/AllenDowney/ThinkPython2/blob/master/code/words.txt
def has3_2consecutive(word):
i = 0; count = 0
while i < len(word) - 1:
if word[i] == word[i+1]:
count = count + 1
if count == 3:
return True
i = i + 2 # Look Here
else:
count = 0
i = i + 1
return False
for line in open("/var/www/python/words.txt"):
word = line.strip()
if has3_2consecutive(word):
print(word)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment