I know i need to use a list comprehension but for the life of me I cannot figure out what would be the correct way to denote this. An example of this running right would be for
The list comprehension gives the letters that have the same letter two places to the right. We simply take the length of the resulting list:
s = "evening" ans = len([x for x in xrange(len(s)-2) if s[x] == s[x+2]]) print ans