Thanks, missed that since it's "above the article". Other things:
- You say in Python 3.7 "order preserving is guaranteed" but following that link I only see Raymond saying "a guarantee for 3.7 is almost inevitable". Am I missing something again or are you overstating that?
- Better remove f2 from the list of functions to test, as it's suuuper slow.
- Would be good to include *min* as well, in addition to mean and median. As Veedrac argued at https://stackoverflow.com/a/24105845/1672429 - "all error in timing is positive [so] the shortest time has the least error in it". And *Raymond* uses min there as well (in his answer, the accepted one).
- I came up with four order-preserving solutions slower than Raymond's but much faster than the others. Then I also found them in the comments of the old blog post, ha. Here they are:
def f13(seq):
seen = set()
add = seen.add
return [add(x) or x for x in seq if x not in seen]
return [add(x) or x for x in seq if not x in seen]
return [x for x in seq if not (x in seen or add(x))]
return [x for x in seq if x not in seen and not add(x)]
Comment
Thanks, missed that since it's "above the article". Other things:
- You say in Python 3.7 "order preserving is guaranteed" but following that link I only see Raymond saying "a guarantee for 3.7 is almost inevitable". Am I missing something again or are you overstating that?
- Better remove f2 from the list of functions to test, as it's suuuper slow.
- Would be good to include *min* as well, in addition to mean and median. As Veedrac argued at https://stackoverflow.com/a/24105845/1672429 - "all error in timing is positive [so] the shortest time has the least error in it". And *Raymond* uses min there as well (in his answer, the accepted one).
- I came up with four order-preserving solutions slower than Raymond's but much faster than the others. Then I also found them in the comments of the old blog post, ha. Here they are:
def f13(seq):
seen = set()
add = seen.add
return [add(x) or x for x in seq if x not in seen]
return [add(x) or x for x in seq if not x in seen]
return [x for x in seq if not (x in seen or add(x))]
return [x for x in seq if x not in seen and not add(x)]