How can I write this C code in Python?

Gerson Kurz gerson.kurz at t-online.de
Sat Feb 2 12:23:18 EST 2002


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()





More information about the Python-list mailing list