Last active
June 5, 2021 14:59
-
-
Save minte9/00ef91be63ed51f80dc90127d994feaf to your computer and use it in GitHub Desktop.
Python / Language / Strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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