For example:
str = 'Hello world. Hello world.'
Turns into:
list = ['!','-','=','~','|']
str = 'He!l-lo wor~ld|.- H~el=lo -w!or~ld.'
                import random
lst = ['!','-','=','~','|']
string = 'Hello world. Hello world.'
print ''.join('%s%s' % (x, random.choice(lst) if random.random() > 0.5 else '') for x in string)
                        Here's an approach that leans towards clarity, but performance-wise may not be optimal.
from random import randint
string = 'Hello world. Hello world.'
for char in ['!','-','=','~','|']:
    pos = randint(0, len(string) - 1)  # pick random position to insert char
    string = "".join((string[:pos], char, string[pos:]))  # insert char at pos
print string
Taken from my answer to a related question which is essentially derived from DrTysra's answer:
from random import choice
S = 'Hello world. Hello world.'
L = ['!','-','=','~','|']
print ''.join('%s%s' % (x, choice((choice(L), ""))) for x in S)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With