You asked for a better way to do the removal. I interpreted it to mean 'shorter, more Pythonic' or something like that.
If we instead are talking about speed, I have a new one for you:
def f7(L,e): ....eLower = e.lower() ....eUpper = e.upper() ....L = [x for x in L if x != eLower and x != eUpper]
I don't know what kind of beast your machine is because my timings are much slower than yours. They tend to vary a little (GC?) but here's a typical run:
Comment
You asked for a better way to do the removal. I interpreted it to mean 'shorter, more Pythonic' or something like that.
If we instead are talking about speed, I have a new one for you:
def f7(L,e):
....eLower = e.lower()
....eUpper = e.upper()
....L = [x for x in L if x != eLower and x != eUpper]
I don't know what kind of beast your machine is because my timings are much slower than yours. They tend to vary a little (GC?) but here's a typical run:
f1 1.59400010109
f2 2.65599989891
f3 2.23399996758
f4 0.921999931335
f5 0.905999898911
f6 1.73400020599
f7 0.43700003624
Please don't announce the winner before the race is over! :)
Replies
This solution works for lists of single characters only! Sorry!