Michael Spencer wrote:
... conv = "".join(char.lower() for char in text if char not in unwanted)

Probably a good place to use str.replace, e.g.

conv = text.lower()
for char in unwanted:
    conv = conv.replace(char, '')

Some timings to support my assertion: =)

C:\Documents and Settings\Steve>python -m timeit -s "s = ''.join(map(str, range(100)))" "s = ''.join(c for c in s if c not in '01')"
10000 loops, best of 3: 74.6 usec per loop


C:\Documents and Settings\Steve>python -m timeit -s "s = ''.join(map(str, range(100)))" "for c in '01': s = s.replace(c, '')"
100000 loops, best of 3: 2.82 usec per loop


Steve
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to