TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Evolution of a Python programmer

366 点作者 r11t超过 15 年前

26 条评论

sophacles超过 15 年前
Web 2.0 programmer:<p><pre><code> import urllib import json def fact(n): res = urllib.urlopen('http://math.org/factorial/?' + urllib.urlencode({'n':n, 'format':'json'})).read() return json.loads(res)['answer'] fact(6) </code></pre> Edit: for a "web scale systems guy" throw an @memcache_memoize in there :)<p>Edit2: fixed a syntax error.<p>Edit3: general cased it. thanks lolcraft!
评论 #1087464 未加载
notaddicted超过 15 年前
<p><pre><code> # "close enough" programmer import math def fact(x): math.sqrt(2*math.pi*n) * math.pow(n/math.e, n) print fact(6) # lazy-er programmer def fact(x): factorials = {6:720} # found on my calculator, add more as they come up if factorials.has_key(x): return factorials[x] else: raise NotImplementedError print fact(6)</code></pre>
评论 #1089861 未加载
shabda超过 15 年前
<a href="http://dis.4chan.org/read/prog/1180084983/" rel="nofollow">http://dis.4chan.org/read/prog/1180084983/</a><p><a href="http://www.hackerne.ws/item?id=1012877" rel="nofollow">http://www.hackerne.ws/item?id=1012877</a><p>Wow the domain can make a huge difference. :)
评论 #1088399 未加载
评论 #1087665 未加载
yan超过 15 年前
The web designer and windows programmer snippets are brilliant.
评论 #1087135 未加载
评论 #1087262 未加载
评论 #1087402 未加载
mrshoe超过 15 年前
I'm proud to be a Lazy Python Programmer... but not lazy enough to skip "What's New in Python 2.5":<p><pre><code> def factorial(x): return x * factorial(x-1) if x &#62; 1 else 1</code></pre>
评论 #1087304 未加载
codexon超过 15 年前
This is an uninspiring ripoff of the older original here:<p><a href="http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html" rel="nofollow">http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer....</a><p>And here is one that is actually well done for Haskell.<p><a href="http://www.willamette.edu/~fruehr/haskell/evolution.html" rel="nofollow">http://www.willamette.edu/~fruehr/haskell/evolution.html</a>
评论 #1088440 未加载
sriramk超过 15 年前
I'm ashamed to admit that I actually learnt something new from this (the @tailcall thing)
评论 #1087378 未加载
alxv超过 15 年前
Functional programmer:<p><pre><code> import operator def factorial(n): return reduce(operator.mul, xrange(1, n+1), 1) print factorial(6) </code></pre> Cutting-edge programmer:<p><pre><code> import math print(math.factorial(6))</code></pre>
评论 #1087581 未加载
评论 #1088505 未加载
alrex021超过 15 年前
Java programmer:<p><pre><code> class FactorialCommand(object): def set_num(self, num): self.__num = num def get_num(self): return self.__num def execute(self): result = 1 i = 2 while i &#60;= self.get_num(): result = result * i i = i + 1 return result cmd = FactorialCommand() cmd.set_num(6) print cmd.execute()</code></pre>
评论 #1087601 未加载
samdk超过 15 年前
The "I find a way to use list comprehensions for everything" Python programmer:<p><pre><code> def fact(n): return eval('*'.join([str(x+1) for x in xrange(n)] + ['1']))</code></pre>
评论 #1087919 未加载
alec超过 15 年前
Where's the one where the Python programmer has to make something go fast and needs to write a C module?
评论 #1088205 未加载
Deestan超过 15 年前
Bored Python programmer:<p><pre><code> def fact(l): return sum(map(bool,reduce(lambda I,l:''.join([l for I in I]), ['+'+'+'*l for l in xrange(l)]))) assert fact(6)==720</code></pre>
Groxx超过 15 年前
I think I'll have to contribute some J code (can anyone uglify Python this much?):<p><pre><code> (*$:@:&#60;:)^:(1&#38;&#60;) 6 </code></pre> Finds the factorial recursively. J programmers are masochists.<p>(From: <a href="http://rosettacode.org/wiki/Factorial_function#Recursive_11" rel="nofollow">http://rosettacode.org/wiki/Factorial_function#Recursive_11</a>)
ajross超过 15 年前
The "first year pascal" example has a metasyntax error. It's missing a "#end" token for symmetry with the C example.
Flow超过 15 年前
So funny. The Windows one makes me wanna abandon computers altogether.
AndrewO超过 15 年前
Doesn't PEP 20 say that there should be only one way to do it? :-)
评论 #1087273 未加载
whyenot超过 15 年前
I don't understand. What's wrong with the factorial function that comes with python?<p><pre><code> from math import factorial </code></pre> done.
评论 #1087604 未加载
Confusion超过 15 年前
I kind of miss an @memoized version
est超过 15 年前
Python one-liner anyone?<p><pre><code> &#62;&#62;&#62; reduce(int.__mul__, range(1,6)) 120</code></pre>
评论 #1088412 未加载
brehaut超过 15 年前
;; python programmer who reads HN and Proggit<p>(defn factorial [n] (reduce * (range 1 (inc n))))
评论 #1087861 未加载
viraptor超过 15 年前
"I've got a lot of memory" or "runtime is more importatant than initialisation" programmer<p><pre><code> fact = init_fact() ... res = fact[x]</code></pre>
jbyers超过 15 年前
Enterprise programmer made me laugh. Especially after spending a few days buried in SAML.
yason超过 15 年前
Heh, this is quite even better than the "Evolution of a programmer".
gregcmartin超过 15 年前
I am going to have to go with Lazier Python programmer
jchonphoenix超过 15 年前
Wonder what a mathematicians python looks like...
评论 #1089941 未加载
评论 #1088203 未加载
gcb超过 15 年前
<a href="http://www.willamette.edu/~fruehr/haskell/evolution.html" rel="nofollow">http://www.willamette.edu/~fruehr/haskell/evolution.html</a><p>for all the closet functional programmers around here :)
评论 #1088202 未加载