Hacker News new | ask | show | jobs
by bkz 5864 days ago
Funny how readable Python is:

def condense(s, remove): return "".join([c for c in s if c != remove])

Cheating (2.6+): s.translate(None, remove)

2 comments

You are aware that this is, to a C programmer, horribly inefficient? (Specifically, it violates the "in-place" requirement, but the actual overhead of that is dwarfed by everything else.)
Either you do it correctly (as in list manipulation, in place) or do it pythonically. That code is somewhere in between.

The pythonic version would be s.replace(c, '')