Thread: Perfect Python
View Single Post
Old Nov 17th, 2006, 5:41 AM   #14
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by DaWei View Post
I think you might agree that some of the forms of some of the abstractions (generators, etc.) approach obscurity without resulting in leaner code or clearer thought.
That's true. On the one hand, list comprehensions can result in clearer code:
python Syntax (Toggle Plain Text)
  1. # Without
  2. urls = []
  3. for tag in soup.fetch_all("a"):
  4. urls.append(tag['href'])
  5.  
  6. # With
  7. urls = [tag['href'] for tag in soup.fetch_all("a")]
On the other hand...
python Syntax (Toggle Plain Text)
  1. def q(s):
  2. if len(s)<=1:return s
  3. return q([l for l in s[1:] if l<s[0]])+[s[0]]+q([g for g in s[1:] if g>=s[0]])
Arevos is offline   Reply With Quote