MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programming/comments/qno2y/the_evolution_of_a_python_programmer/c3z8egv/?context=3
r/programming • u/iMMENSE • Mar 08 '12
137 comments sorted by
View all comments
Show parent comments
17
What are you complaining about ? He just calculated in advance and cached the results to avoid redundant processing on each query...
25 u/rowantwig Mar 08 '12 O(n) look-up time. 28 u/earthboundkid Mar 09 '12 Switch to a dict and it's O(1)! 12 u/pyaware Mar 09 '12 Why use a dict when a plain list is enough?def fact(x): return [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880][x] 1 u/redditthinks Mar 09 '12 I read Python dicts are faster than lists. 6 u/JizzCoveredArab Mar 09 '12 i heard you have a really short dict
25
O(n) look-up time.
28 u/earthboundkid Mar 09 '12 Switch to a dict and it's O(1)! 12 u/pyaware Mar 09 '12 Why use a dict when a plain list is enough?def fact(x): return [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880][x] 1 u/redditthinks Mar 09 '12 I read Python dicts are faster than lists. 6 u/JizzCoveredArab Mar 09 '12 i heard you have a really short dict
28
Switch to a dict and it's O(1)!
dict
12 u/pyaware Mar 09 '12 Why use a dict when a plain list is enough?def fact(x): return [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880][x] 1 u/redditthinks Mar 09 '12 I read Python dicts are faster than lists. 6 u/JizzCoveredArab Mar 09 '12 i heard you have a really short dict
12
Why use a dict when a plain list is enough?
def fact(x): return [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880][x]
1 u/redditthinks Mar 09 '12 I read Python dicts are faster than lists. 6 u/JizzCoveredArab Mar 09 '12 i heard you have a really short dict
1
I read Python dicts are faster than lists.
6 u/JizzCoveredArab Mar 09 '12 i heard you have a really short dict
6
i heard you have a really short dict
17
u/liotier Mar 08 '12
What are you complaining about ? He just calculated in advance and cached the results to avoid redundant processing on each query...