If you don't care about letters and spaces:
''.join(phrase[i-1] if i % 3 or i == 0 else phrase[i-1].upper() for i in range(1, len(phrase) + 1))
If you only want to count letters:
new_phrase = ''
phrase = "here are some words"
counter = 0
for c in phrase:
if not c.isalpha():
new_phrase += c
else:
counter += 1
if not counter % 3:
new_phrase += c.upper()
else:
new_phrase += c
Since your example shows you using swapcase() instead of upper(), you can just replace upper() with swapcase() in this code to achieve that functionality if that's what you want.