I have been using the python challenge to teach myself python as my first programming/scripting language outside of HTML. As I go along, I find that while I'm understanding the concepts rather well, I am not being as efficient as I could be. While the code I whip up gets things done, the suggestions others have shared with me make me thing that python can be as simple as speaking in english.
Case in point:
from string import ascii_letters import re, urllib2, webbrowser as wb wb.open('http://www.pythonchallenge.com/pc/def/%s.html' % ''.join(chr for chr in re.findall('<!--(.*?)-->', urllib2.urlopen('http://www.pythonchallenge.com/pc/def/ocr.html') .read(), re.S) if chr in ascii_letters))
This snippet was suggested to me for the 2nd puzzle. If I read it (although it's organized differently), it comes back like this:
Importing ASCII letters from string, re, and urllib2 modules and webrowser as wb, here is what we want to do:
*open the url http://www.pythonchallenge.com/pc/def/ocr.html
*read the source and find all unique ascii characters between <!-- and --!>
*join those characters and replace % in the following url
Is this correct? My problem is that when I come up with an idea for a program, while I can get it done, there is usually a way to accomplish the same goal in much less code. How do you learn what to use when?