[Baypiggies] Code/Idea Review (WARNING: SPOILER)
Glen Jarvis
glen at glenjarvis.com
Sat Dec 15 20:23:02 CET 2007
As a recent transplant to the Bay Area, I must say that I never
realized how much of a geek haven this was. I knew it would be richer
in geeks, but I did not know moving here would be one of the smartest
decisions I ever made!
I went to my second Bay Piggies meeting. And, I had an incredible
time. JJ was absolutely awesome and allowed me to ride with him. And,
he, his co-worker, several people he socialized with, and myself had
some incredible conversations for several hours. You can't help but
genuinely like all of these guys. They're fun to talk to, smart, and
just 'get it' instead of getting board or eyes glassing over.
And, I'm usually a very big duck in a little puddle. At BayPIGgies,
I'm an itty bitty new duckling, wet behind the ears. And, there are
so many people who genuinely want to help.
I learned two really incredible things this time: PEP-8 and the
Python Challenge. Because of the talk, I discovered the Python
Challenge (http://www.pythonchallenge.com/). What a great way to
challenge ourselves. The first two (0, and 1) were real easy
challenges. However, instead of just marching on, I am trying to be a
code nazi. I want to keep the code for each of these challenges, I
want it to pass a PEP-8 level code review, and I want it to be the
most 'intelligent' choice for the objective.
In challenge 1, I was able to create some python code fairly quickly
to translate the text enough to catch the gist fairly quickly.
However, as a typical non-python coder, I used a loop instead of
string.maketrans(). After reading the string module help, I was able
to keep reducing and rewriting this until it was closer to what I
thought the challenge wanted us to do.
I would like it, if you don't mind, if you gave me a thorough peer
review for such a small piece of code. I want to know anytime I break
convention with PEP-8. Also, if I received replies like "crap code,
dude." that, unfortunately is not helpful. What would be helpful if I
heard *why* it was crap so I could learn from it. The same is true
for "cool code." That doesn't tell me what my weaknesses or strengths
are.
I believe lines 6 and 7 can be reduced to be more readable and better
written. If any (or all) can oblige, I would love to learn. Be
warned, however, that this is a solution to the second Python
Challenge. You should do the first two challenges yourself so there
are no spoilers.
I *heart* BayPIGgies!
Cheers,
Glen
Chief Gumby on a Bicycle (i.e., the dork who has a busted shoulder)
--
415-680-3964
glen at glenjarvis.com
http://www.glenjarvis.com
"You must be the change you wish to see in the world." -M. Gandhi
1 #!/usr/bin/env python
2
3 import sys
4 import string
5
6 alpha_list=map(chr, range(ord('a'), ord('z') + 1))
7 alphabet_=string.join(alpha_list, '')
8
9 re_map=alphabet_[2:] + alphabet_[:2]
10
11 trans_table = string.maketrans( alphabet_, re_map)
12
13 print "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr
amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw
rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu
ynnjw ml rfc spj.".translate(trans_table)
More information about the Baypiggies
mailing list