Answer the question
In order to leave comments, you need to log in
How to write a condition for counting identical adjacent characters in a string?
Greetings.
Tell me how to write a condition for counting identical adjacent characters in a string, for example, if there are more than 3 repeated letters or numbers in a string, then the condition is met. Upper or lower case is not important.
Examples:
Paaassword - the condition will be met
Paaaassword - the condition will be met
P111ssword - the condition will be met
Password - the condition will not be met
Answer the question
In order to leave comments, you need to log in
passw = 'PasssWword'
def ifTriple(word):
for i in range(1, len(word)-1):
if(word[i].lower() == word[i-1].lower() and word[i].lower() == word[i+1].lower() ):
return True
return False
print(ifTriple(passw))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question