World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Neha Kumawat
a year ago
import random
import re
def replace(t):
inner_word = list(t.group(2))
random.shuffle(inner_word)
return t.group(1) + "".join(inner_word) + t.group(3)
text = "Hello, You should reach the finish line."
print re.sub(r"(\w)(\w+)(\w)", replace, text)
print re.sub(r"(\w)(\w+)(\w)", replace, text)
Hlleo, You slouhd raech the fsiinh lnie.
Hlleo, You suolhd raceh the fniish line.