pythontextpython-3.6zalgo

Convert Zalgo Text to Plain text


So I have some zalgo text:

Ḩ̡̤̜̩̜̝̉é̪̟̜̗̣̔̊̋̈̅ll̪̟̣̗̣̗̜̜̇̌̋̔̍̉̃̌̏̄̔ọ̘̥̗̇̂̒

and I'm trying to turn that into

Hello

Using python3.6, the function I'm using to convert text to zalgo is

def zalgo(text):
    return ''.join([v,v+''.join(choice(list(map(chr,range(768,815))))for i in range(int(normalvariate(10,5))))][v.isalpha()]for v in text)

Taken from a code-golf question.

What I'm trying to do is get the string back in python3.6 so the example would return Hello


Solution

  • You may filter the alphabets/digits from your string using str.isalnum (or str.isalpha for only alphabets) and join it back as:

    >>> my_str = 'Ḩ̡̤̜̩̜̝̉é̪̟̜̗̣̔̊̋̈̅ll̪̟̣̗̣̗̜̜̇̌̋̔̍̉̃̌̏̄̔ọ̘̥̗̇̂̒'
    
    
    >>> ''.join(filter(str.isalnum, my_str))
    'Hello'