[Python-ideas] adding a trim convenience function

Terry Reedy tjreedy at udel.edu
Thu Mar 6 20:37:17 CET 2008

"Erick Tryzelaar" 
<idadesub at users.sourceforge.net> wrote in 
message | On Wed, Mar 5, 2008 at 1:33 PM, Terry Reedy 
<tjreedy at udel.edu> wrote:
| > >>> [site.replace('http://', '')for site in sites]
| > ['www.google.com', 'python.org', 'www.yahoo.com']
| Unfortunately that would break down in certain cases with a different
| strings, like 'foo bar foo'.replace('foo', ''), which just results in
| ' bar '.

I knew that, of course, but that objection does not apply to the use case 
you presented.  I simply gave the simplest thing that worked, that passed 
your 'test'.
Tal gave a more general answer.

| >  Try another use case.  I think str pretty well has the basic tools 
| >  to construct whatever specific tools one needs.
| Oh sure it can, considering that I can implement ltrim in three lines.
| This is just to reduce a common pattern in my code, and to remove
| rewriting it in multiple projects.

Who many such uses are like your 'foo bar for'?


More information about the Python-ideas mailing list