Answers for "create a typo with python"

0

create a typo with python

import string
import random

new_phrase = []
words = phrase.split(' ')
for word in words:
    outcome = random.random()
    if outcome <= p:
        ix = random.choice(range(len(word)))
        new_word = ''.join([word[w] if w != ix else random.choice(string.ascii_letters) for w in range(len(word))])
        new_phrase.append(new_word)
    else:
        new_phrase.append(word)

new_phrase = ' '.join([w for w in new_phrase])
Posted by: Guest on May-24-2020

Code answers related to "create a typo with python"

Python Answers by Framework

Browse Popular Code Answers by Language