Capitalize every 3rd letter in a string - Python -


i'm beginning learn python, please bear me. math knowledge little shaky well. i'm able capitalize single word, or first word in string. having problem need capitalize every 3rd letter in string. need function. i've used this, can change letter in 1 word, not every 3rd.

x = "string" y = x[:3] + x[3].swapcase() + x[4:]  

there sample template used

if in phrase (len(phrase)) 

but i'm not sure how works.

i'd output show "this texting function"

thanks in advance help.

you can take stride slice of array makes pretty , pythonic few lines:

s = "thisisareallylongstringwithlotsofletters"    # convert list = list(s)  #change every third letter in place list comprehension a[2::3] = [x.upper() x in a[2::3]]  #back string s = ''.join(a)  # result: thisisareallylongstringwithlotsofletters 

it's not clear want spaces - treats them characters.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -