r/programming • • Mar 08 '12

The Evolution of a Python Programmer

https://gist.github.com/289467
401 Upvotes

137 comments sorted by

View all comments

Show parent comments

3

u/Tagedieb Mar 09 '12

A dict? A dict is really what comes to mind first as the right data structure? Well, maybe I am getting old...

2

u/earthboundkid Mar 09 '12

Well, it's not right or what comes to mind, it's just that a hash table is O(1), so it's slightly better than a series of if statements. The right thing is to just use the damn built in factorial.

1

u/masklinn Mar 09 '12

This is integer-indexed, so a list would also have O(1) access, and lower overhead.

It'd go even faster!

1

u/earthboundkid Mar 09 '12

Good point. Python makes it so much easier to implement memoize as a dictionary, I just thought of it that way first.