How To Introduce Typo In A String?
I would like to introduce typos in a string. I have a parameter typo_prob which would flip a character in a string with a probability of typo_prob. For example, if typo_prob is 0.1
Solution 1:
import random
import string
message = "Where do you live?"
message = list(message)
for pos, char in enumerate(message):
message[pos] = random.choice(string.ascii_lowercase) if random.random() < 0.1 else char
message = "".join(message)
Post a Comment for "How To Introduce Typo In A String?"