How can I write this C code in Python?

Martijn Faassen m.faassen at vet.uu.nl
Sun Feb 3 07:43:14 EST 2002


Gerson Kurz <gerson.kurz at t-online.de> wrote:
> On Sat, 2 Feb 2002 09:16:32 -0600, "Jason Orendorff"
> <jason at jorendorff.com> wrote:

>>Fred wrote:
>>> I think if I could see the below C code done in Python it
>>> would get me over the beginners hump.
>>
>>for i in range(1, 13):
>>    for j in range(1, 13):
>>        print "%4d" % (i*j),
>>    print
>>
>>## Jason Orendorff    http://www.jorendorff.com/
>>
> Alternatively, you can always write

> for n in range(12):
>    exec("abcdefghijkl"[n]+"=lambda x=0,y=0: "+filter(
>        lambda x:x not in "\n$\r","""(x*y#x/x!range(x,
> y#x+y!b(1,1#d(e~,e~#d(f~,f~#c(e~,e~+d(g~,d(g~,g~))#"%4
> d" % a(x,y#map(lambda y:i(x,y),h~#" ".join(j(x)#"\\n".
> join(map(k,h~))""".replace("~","()").replace("#",")!")
>        ).split("!")[n])
> print l()

Yay! TIMTOWTDI!!

I like how this way uses Darting's descent to reach an algorithmic
solipcism, not even needing to use the time travel module to reach 
subtler but in the end much more impressive segue. Also nice use of
the Meta Abstraction pattern!

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list