Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Randomizing BBCode

Name: Anonymous 2011-08-09 9:58

https://gist.github.com/1132093

How can I improve this?

WARNING: FIOC

Name: Anonymous 2011-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)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List