Skip to content

Instantly share code, notes, and snippets.

@adibenc
Created March 5, 2021 04:46
Show Gist options
  • Save adibenc/717638040ecd3c3ad1f89f8b68329f22 to your computer and use it in GitHub Desktop.
Save adibenc/717638040ecd3c3ad1f89f8b68329f22 to your computer and use it in GitHub Desktop.
messize.py
#!/usr/bin/python3
import random
sentence="""[wiki] A typographical error (often shortened to typo), also called misprint, is a mistake (such as a spelling mistake)[1] made in the typing of printed (or electronic) material. Historically, this referred to mistakes in manual type-setting (typography). The term includes errors due to mechanical failure or slips of the hand or finger,[2] but excludes errors of ignorance, such as spelling errors, or changing and misuse of words such as "than" and "then". Before the arrival of printing, the "copyist's mistake" or "scribal error" was the equivalent for manuscripts. Most typos involve simple duplication, omission, transposition, or substitution of a small number of characters."""
sentence="""but magically we still can interpret what is written."""
# sentence=""" """
print(sentence)
words = sentence.split(" ")
# suf1, suf2
def messize(w, preflen = 4, mid1 = 2, midlen = 4, suflen = 2):
# print(w)
maxlen = len(w)-1
mid1 = preflen
midlen = maxlen - suflen + 1
middle = list(w[mid1:midlen])
middle = sorted(middle, key = lambda x: random.random())
middle = "".join(middle)
wpref = w[0:preflen]
wsuf = w[-suflen:]
messy = wpref + middle + wsuf
return messy
def messFilter(w):
wlen = len(w)
if wlen <= 4 or wlen >= 21:
return w
elif wlen < 8:
return messize(w, 2)
elif wlen >= 8 and wlen < 21:
return messize(w)
messed = []
for w in words:
messy = messFilter(w)
messed.append(messy)
print(" ".join(messed))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment