Re: Find and Replace Simplification

2013-07-21 Thread Joshua Landau
On 21 July 2013 13:28, Serhiy Storchaka wrote: > 21.07.13 14:29, Joshua Landau написав(ла): > >> On 21 July 2013 08:44, Serhiy Storchaka wrote: >>> >>> 20.07.13 20:03, Joshua Landau написав(ла): >>> Still, it seems to me that it should be optimizable for sensible builtin types such that

Re: Find and Replace Simplification

2013-07-21 Thread Serhiy Storchaka
21.07.13 14:29, Joshua Landau написав(ла): On 21 July 2013 08:44, Serhiy Storchaka wrote: 20.07.13 20:03, Joshua Landau написав(ла): Still, it seems to me that it should be optimizable for sensible builtin types such that .translate is significantly faster, as there's no theoretical extra wor

Re: Find and Replace Simplification

2013-07-21 Thread Joshua Landau
On 21 July 2013 08:44, Serhiy Storchaka wrote: > 20.07.13 20:03, Joshua Landau написав(ла): > >> Still, it seems to me that it should be optimizable for sensible >> builtin types such that .translate is significantly faster, as there's >> no theoretical extra work that .translate *has* to do that

Re: Find and Replace Simplification

2013-07-21 Thread Serhiy Storchaka
20.07.13 20:03, Joshua Landau написав(ла): Still, it seems to me that it should be optimizable for sensible builtin types such that .translate is significantly faster, as there's no theoretical extra work that .translate *has* to do that .replace does not, and .replace also has to rebuild the str

Re: Find and Replace Simplification

2013-07-20 Thread Joshua Landau
On 20 July 2013 22:56, Dave Angel wrote: > On 07/20/2013 02:37 PM, Joshua Landau wrote: >> >> The problem can be solved, I'd imagine, for builtin types. Just build >> an internal representation upon calling .translate that's faster. It's >> especially easy in the list case > > What "list case"? l

Re: Find and Replace Simplification

2013-07-20 Thread Dave Angel
On 07/20/2013 02:37 PM, Joshua Landau wrote: On 20 July 2013 19:04, Dave Angel wrote: On 07/20/2013 01:03 PM, Joshua Landau wrote: Still, it seems to me that it should be optimizable for sensible builtin types such that .translate is significantly faster, as there's no theoretical extra work

Re: Find and Replace Simplification

2013-07-20 Thread Joshua Landau
On 20 July 2013 19:37, Joshua Landau wrote: > mapping int -> int Well, on second thought it's not quite this unless it's a 1:1 mapping. Point remains valid, though, I think. -- http://mail.python.org/mailman/listinfo/python-list

Re: Find and Replace Simplification

2013-07-20 Thread Joshua Landau
On 20 July 2013 19:04, Dave Angel wrote: > On 07/20/2013 01:03 PM, Joshua Landau wrote: >> >> Still, it seems to me that it should be optimizable for sensible >> builtin types such that .translate is significantly faster, as there's >> no theoretical extra work that .translate *has* to do that .re

Re: Find and Replace Simplification

2013-07-20 Thread Dave Angel
On 07/20/2013 01:03 PM, Joshua Landau wrote: On 20 July 2013 12:57, Serhiy Storchaka wrote: 20.07.13 14:16, Joshua Landau написав(ла): However, some quick timing shows that translate has a very high penalty for missing characters and is a tad slower any way. Really, though, there sh

Re: Find and Replace Simplification

2013-07-20 Thread Joshua Landau
On 20 July 2013 12:57, Serhiy Storchaka wrote: > 20.07.13 14:16, Joshua Landau написав(ла): >> >> On 19 July 2013 18:29, Serhiy Storchaka wrote: >>> >>> The string replace() method is fastest (at least in Python 3.3+). See >>> implementation of html.escape() etc. >> >> >> def escape(s, quote=True

Re: Find and Replace Simplification

2013-07-20 Thread Devyn Collier Johnson
On 07/20/2013 07:48 AM, Serhiy Storchaka wrote: 19.07.13 21:08, Skip Montanaro написав(ла): Serhiy> The string replace() method is fastest (at least in Python 3.3+). See Serhiy> implementation of html.escape() etc. I trust everybody knows by now that when you want to use regular expressions yo

Re: Find and Replace Simplification

2013-07-20 Thread Devyn Collier Johnson
On 07/20/2013 07:16 AM, Joshua Landau wrote: On 19 July 2013 18:29, Serhiy Storchaka wrote: 19.07.13 19:22, Steven D'Aprano написав(ла): I also expect that the string replace() method will be second fastest, and re.sub will be the slowest, by a very long way. The string replace() method is

Re: Find and Replace Simplification

2013-07-20 Thread Serhiy Storchaka
20.07.13 14:16, Joshua Landau написав(ла): On 19 July 2013 18:29, Serhiy Storchaka wrote: The string replace() method is fastest (at least in Python 3.3+). See implementation of html.escape() etc. def escape(s, quote=True): if quote: return s.translate(_escape_map_full) ret

Re: Find and Replace Simplification

2013-07-20 Thread Serhiy Storchaka
19.07.13 21:08, Skip Montanaro написав(ла): Serhiy> The string replace() method is fastest (at least in Python 3.3+). See Serhiy> implementation of html.escape() etc. I trust everybody knows by now that when you want to use regular expressions you should shell out to Perl for the best performance

Re: Find and Replace Simplification

2013-07-20 Thread Joshua Landau
On 19 July 2013 18:29, Serhiy Storchaka wrote: > 19.07.13 19:22, Steven D'Aprano написав(ла): > >> I also expect that the string replace() method will be second fastest, >> and re.sub will be the slowest, by a very long way. > > > The string replace() method is fastest (at least in Python 3.3+). S

Re: Find and Replace Simplification

2013-07-19 Thread Dave Angel
On 07/19/2013 05:44 PM, Devyn Collier Johnson wrote: On 07/19/2013 12:22 PM, Steven D'Aprano wrote: On Fri, 19 Jul 2013 09:22:48 -0400, Devyn Collier Johnson wrote: I have some code that I want to simplify. I know that a for-loop would work well, but can I make re.sub perform all of the below

Re: Find and Replace Simplification

2013-07-19 Thread Devyn Collier Johnson
On 07/19/2013 12:22 PM, Steven D'Aprano wrote: On Fri, 19 Jul 2013 09:22:48 -0400, Devyn Collier Johnson wrote: I have some code that I want to simplify. I know that a for-loop would work well, but can I make re.sub perform all of the below tasks at once, or can I write this in a way that is m

Re: Find and Replace Simplification

2013-07-19 Thread Skip Montanaro
Serhiy> The string replace() method is fastest (at least in Python 3.3+). See Serhiy> implementation of html.escape() etc. I trust everybody knows by now that when you want to use regular expressions you should shell out to Perl for the best performance. :-) Skip -- http://mail.python.org/mailma

Re: Find and Replace Simplification

2013-07-19 Thread Serhiy Storchaka
19.07.13 19:22, Steven D'Aprano написав(ла): I also expect that the string replace() method will be second fastest, and re.sub will be the slowest, by a very long way. The string replace() method is fastest (at least in Python 3.3+). See implementation of html.escape() etc. -- http://mail.p

Re: Find and Replace Simplification

2013-07-19 Thread Steven D'Aprano
On Fri, 19 Jul 2013 09:22:48 -0400, Devyn Collier Johnson wrote: > I have some code that I want to simplify. I know that a for-loop would > work well, but can I make re.sub perform all of the below tasks at once, > or can I write this in a way that is more efficient than using a > for-loop? > > D

Re: Find and Replace Simplification

2013-07-19 Thread John Gordon
In Devyn Collier Johnson writes: > I have some code that I want to simplify. I know that a for-loop would > work well, but can I make re.sub perform all of the below tasks at once, > or can I write this in a way that is more efficient than using a for-loop? > DATA = re.sub(',', '', 'DATA') >

Re: Find and Replace Simplification

2013-07-19 Thread Novocastrian_Nomad
On Friday, July 19, 2013 7:22:48 AM UTC-6, Devyn Collier Johnson wrote: > I have some code that I want to simplify. I know that a for-loop would > > work well, but can I make re.sub perform all of the below tasks at once, > or can I write this in a way that is more efficient than using a for-loo

Find and Replace Simplification

2013-07-19 Thread Devyn Collier Johnson
I have some code that I want to simplify. I know that a for-loop would work well, but can I make re.sub perform all of the below tasks at once, or can I write this in a way that is more efficient than using a for-loop? DATA = re.sub(',', '', 'DATA') DATA = re.sub('\'', '', 'DATA') DATA = re.sub