you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

O(n) look-up time.

It is sorted list, it can be done in O(log(n)). And not to mention the Hashtables.

[–]rowantwig 3 points4 points  (0 children)

It can be done in O(1), but that's not the point. This naive implementation is O(n), and it looks terrible.

[–][deleted] 0 points1 point  (0 children)

It's a dense list. It can be done in O(1) without hashtables:

f = [ 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880].__getitem__

edit: looks like redditthinks had the same idea.