Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active June 5, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minte9/00ef91be63ed51f80dc90127d994feaf to your computer and use it in GitHub Desktop.
Save minte9/00ef91be63ed51f80dc90127d994feaf to your computer and use it in GitHub Desktop.
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