I am trying to find consecutive letters in an entered string:
if a string contains three consecutive letters based on the layout of a UK QWERTY keyboard then a variable is given 5 points for each set of three.
e.g. asdFG would contain three consecutive sets. upper and lowercase do not matter.
can you please help as don't know where to begin with this?
The easiest way would be to first generate all possible triples:
If you only want the characters and not numbers and brackets etc., substitute the
lines
above withNow that we have all the triples, you can check with
count
how many times a triple occurs in inputed string.Bam, there you go. What this does is it counts for each triple how many times it occurs in a string so you know how many times to add 5 points. We use
str.lower()
to convert all characters to lowercase because as you said, capitalization does not matter.If it is the same whether a string contains a certain triple once or three times, then you can do this: