Splitting on a word

Bernhard Holzmayer Holzmayer.Bernhard at deadspam.com
Thu Jul 14 15:39:22 CEST 2005

qwweeeit at yahoo.it wrote:

> Bernard... don't get angry, but I prefer the solution of Joe.  

Oh. If I got angry in such a case, I would have stopped responding to such
posts long ago 
You know the background... and you'll have to bear the consequences. ;-) 

> ... 
> for me "pythonic" means simple and short (I may be wrong...).

It's your definition, isn't it? 
One of the most important advantages of Python (for me!) besides its
readability is that it comes with "Batteries included", which means, that I
can benefit of the work others did before, and that I can rely on its

The solution which I proposed is nothing but the test code from htmllib,
stripped down to the absolut minimum, enriched with the print command
to show the anchor list.

If I had to write production-level code of your sort, I'd take such an
off-the-shelf solution, because it minimizes the risk of failures.

Think only of such issues like these:
- does your code find a tag like <A HREF= (capital letters)?
- does your code correctly handle incomplete tags like
   <a href="linkadr"></a> or references with/without " ...?
- does it survive ill-coded html after all?

I've made the experience that it's usually better to rely on such
"library" code than to reinvent the wheel.

There's often a reason to take another approach.
I'd agree that a simple and short solution is fascinating.
However, every simple and short solution should be readable.
As a terrific example, here's a very tiny piece of code,
which does nothing but calculate the prime numbers up to 1000:

print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,
   map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),

- simple (depends on your familiarity with stuff like map and lambda) 
- short (compared with different solutions) 
- and veeerrrryyy pythonic!


More information about the Python-list mailing list