Re: [Python-ideas] Consider generalizing Decimal to support arbitrary radix

2018-02-08 Thread Greg Ewing
Mark Dickinson wrote: And base-16 floating-point is still used in current IBM hardware, but I don't know whether that's purely for historical/backwards-compatibility reasons, or because it's faster for the FPU. Historically, base 16 was used to get a bigger exponent range for a given number of

Re: [Python-ideas] Consider generalizing Decimal to support arbitrary radix

2018-02-08 Thread Mark Dickinson
On Wed, Feb 7, 2018 at 10:50 PM, Steven D'Aprano wrote: > Why? > > There are clear advantages to floating point arithmetic done in base 2 > (speed, minimum possible rounding error, least amount of wobble), and a > different advantage to floating point done in base 10 (matches exactly > the standa

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Franklin? Lee
On Feb 8, 2018 13:06, "Serhiy Storchaka" wrote: 08.02.18 12:45, Franklin? Lee пише: > Could it be that re uses an optimization that can also be used in str? > CPython uses a modified Boyer-Moore for str.find: > https://github.com/python/cpython/blob/master/Objects/string > lib/fastsearch.h > htt

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Franklin? Lee
On Thu, Feb 8, 2018 at 5:45 AM, Franklin? Lee wrote: > On Feb 7, 2018 17:28, "Serhiy Storchaka" wrote: > > The name of complicated str methods is regular expressions. For doing these > > operations efficiently you need to convert arguments in special optimized > > form. This is what re.compile()

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Serhiy Storchaka
08.02.18 12:45, Franklin? Lee пише: On Feb 7, 2018 17:28, "Serhiy Storchaka" > wrote: Even for simple string search a regular expression can be more efficient than a str method. $ ./python -m timeit -s 'import re; p = re.compile("spam"); s = "spa"*100

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread INADA Naoki
I think it shouldn't be str's method. They should be separate class to reuse internal tree. There are some Aho Corasick implementation on PyPI. As far as I know, AC is longest match. On the other hand, Go's replacer (it's trie based too) is: > Replacements are performed in order, without overla

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Franklin? Lee
On Thu, Feb 8, 2018 at 11:24 AM, Steve Dower wrote: > Easily fixed by installing one of the alternate regex libraries. MRAB's regex library, the most prominent alternative, does not use the linear-time search algorithm. The only libraries I know that do are the ones with re2, though I haven't loo

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Steve Dower
Easily fixed by installing one of the alternate regex libraries. re performance and its edge cases have been discussed endlessly. Please look it up before restarting that discussion. Top-posted from my Windows phone From: Franklin? Lee Sent: Thursday, February 8, 2018 2:46 To: Serhiy Storchaka

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Sven R. Kunze
Same here. On 07.02.2018 22:57, Mike Miller wrote: +1 I have the need for one or two of these in every project (of a certain size) and have to come up with solutions each time with the re module or a loop. Not a fan of regex's for trivial tasks, or those that require a real parser. On 20

Re: [Python-ideas] Complicate str methods

2018-02-08 Thread Franklin? Lee
On Feb 7, 2018 17:28, "Serhiy Storchaka" wrote: 04.02.18 00:04, Franklin? Lee пише: Let s be a str. I propose to allow these existing str methods to take > params in new forms. > > s.replace(old, new): > Allow passing in a collection of olds. > Allow passing in a single argument, a map