Interesting,
I should add that maketrans and translate can benefit form some examples in the documentation.
:)
I should add that maketrans and translate can benefit form some examples in the documentation.
:)
(Oct-04-2020, 01:14 AM)scidam Wrote:str.translate
is a bit faster...:
(scidev) dmitry@linux-mh4h:~/workspace/scipy> python -m timeit "'ajklbdkjsbc'.translate(str.maketrans('','','abc'))" 500000 loops, best of 5: 545 nsec per loop (scidev) dmitry@linux-mh4h:~/workspace/scipy> python -m timeit "''.join([c for c in 'ajklbdkjsbc' if c not in 'abc'])" 500000 loops, best of 5: 572 nsec per loop