Try applying some split
, and a lambda
as below, and then join
.
>>> x = "this texting function"
>>> " ".join(map(lambda w: w[:2] + w[2].swapcase() + w[3:], x.split()))
'thIs teXting fuNction'
If you are not a fan of lambda, then you can write a method like this
>>> def swapcase_3rd(string):
... if len(string) >3:
... return string[:2] + string[2].swapcase() + string[3:]
... if len(string) == 3:
... return string[:2] + string[2].swapcase()
... return string
...
>>> x = "this texting function"
>>> " ".join(map(swapcase_3rd, x.split()))
'thIs teXting fuNction'