12 ms·
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)
by bkz 16y 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)
- JoachimSchipper 16y agoYou 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.)
- zepolen 16y agoEither 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, '')