OP here, glad someone made a better version because I've only just started really learning programming, and so I'm sure my version is full of ``amateur mistakes".
Anyway, this is fun but it sure can't beat MANUAL HANDCRAFTED EXPERT BBCODE.
Tidied up your FIOC a bit, then rewrote most of it:
import random, sys
tags = 'b u i o sup sub spoiler m aa s'.split()
ransom = ''
for c in sys.stdin.read():
amount = random.randint(0, 5)
for tag in random.sample(tags, amount):
c = '[{0}]{1}[/{0}]'.format(tag, c)
ransom += c
print ransom
Name:
Anonymous2011-08-09 14:54
>>11
Not that it matters too much for something like this, but it's considered bad practice to have a loop that concatenates to a string in Python. It reallocates a new string each iteration and it's slow. This is the way that won't get you bitched at when working with a team of Pythonistas.
import random, sys
tags = 'b u i o sup sub spoiler m aa s'.split()
ransom = []
for c in sys.stdin.read():
amount = random.randint(0, 5)
for tag in random.sample(tags, amount):
c = '[{0}]{1}[/{0}]'.format(tag, c)
ransom.append(c)
print ''.join(ransom)
from random import randint as r,sample as s;from sys import argv as a,stdin as i
print ''.join(map(lambda c,f=lambda c,t,f=lambda c,t,f:c if not t else '[{0}]{1'
'}[/{0}]'.format(t.pop(),f(c,t,f)): f(c,t,f):f(c,s('b u i o sup sub spoiler m a'
'a s'.split(),r(0,5))),' '.join(a[1:]) or i.read()))
Name:
Anonymous2011-08-09 20:39
>>15
Don't you have some useless C code that does nothing to optimize?