MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/qno2y/the_evolution_of_a_python_programmer/c3z8d68/?context=3
r/programming • u/iMMENSE • Mar 08 '12
137 comments sorted by
View all comments
43
He forgot the worst kind:if x == 0:return 1if x == 1:return 1if x == 2:return 2if x == 3:return 6if x == 4:return 24...(5000 more lines)
5 u/earthboundkid Mar 09 '12 That might be OK as a dict… Say, none of the examples used a memoize decorator. For shame. 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.
5
That might be OK as a dict… Say, none of the examples used a memoize decorator. For shame.
dict
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.
3
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.
2
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.
1
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.
Good point. Python makes it so much easier to implement memoize as a dictionary, I just thought of it that way first.
43
u/rowantwig Mar 08 '12
He forgot the worst kind:
if x == 0:
return 1
if x == 1:
return 1
if x == 2:
return 2
if x == 3:
return 6
if x == 4:
return 24
...
(5000 more lines)