Re: A more

2019-11-14 Thread Terry Reedy
On 11/14/2019 10:24 AM, James Lu wrote: Where do I go to find a more complete specification for Python? The Cpython code, the tests, and its actual behavior. I want to learn about common semi-internal language features used by popular libraries, because I am reimplementing Python. The refere

Re: a more precise distance algorithm

2015-05-27 Thread Oscar Benjamin
On 27 May 2015 at 19:00, Brian Blais wrote: > On Mon, May 25, 2015 at 11:11 PM, Steven D'Aprano wrote: >> >> Let's compare three methods. >> >> def naive(a, b): >> return math.sqrt(a**2 + b**2) >> >> def alternate(a, b): >> a, b = min(a, b), max(a, b) >> if a == 0: return b >> if

Re: a more precise distance algorithm

2015-05-27 Thread Brian Blais
On Mon, May 25, 2015 at 11:11 PM, Steven D'Aprano wrote: > > Let's compare three methods. > > def naive(a, b): > return math.sqrt(a**2 + b**2) > > def alternate(a, b): > a, b = min(a, b), max(a, b) > if a == 0: return b > if b == 0: return a > return a * math.sqrt(1 + b**2 /

Re: a more precise distance algorithm

2015-05-27 Thread Robin Becker
A minor point is that if you just need to compare distances you don't need to compute the hypotenuse, its square will do so no subtractions etc etc. -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list

Re: a more precise distance algorithm

2015-05-26 Thread random832
On Tue, May 26, 2015, at 09:40, random...@fastmail.us wrote: > On Mon, May 25, 2015, at 15:21, ravas wrote: > > Is this valid? Does it apply to python? > > Any other thoughts? :D > > The math.hypot function uses the C library's function which should deal > with such concerns internally. There is a

Re: a more precise distance algorithm

2015-05-26 Thread random832
On Mon, May 25, 2015, at 15:21, ravas wrote: > Is this valid? Does it apply to python? > Any other thoughts? :D The math.hypot function uses the C library's function which should deal with such concerns internally. There is a fallback version in case the C library does not have this function, in P

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 10:16:02 PM UTC-7, Gary Herron wrote: > It's probably not the square root that's causing the inaccuracies. In > many other cases, and probably here also, it's the summing of two > numbers that have vastly different values that loses precision. A > demonstration: > >

Re: a more precise distance algorithm

2015-05-25 Thread Christian Gollwitzer
Am 26.05.15 um 05:11 schrieb Steven D'Aprano: mismatch after 3 trials naive: 767.3916150255787 alternate: 767.3916150255789 hypot: 767.3916150255787 which shows that: (1) It's not hard to find mismatches; (2) It's not obvious which of the three methods is more accurate. The main problem is

Re: a more precise distance algorithm

2015-05-25 Thread Gary Herron
On 05/25/2015 09:13 PM, ravas wrote: On Monday, May 25, 2015 at 8:11:25 PM UTC-7, Steven D'Aprano wrote: Let's compare three methods. ... which shows that: (1) It's not hard to find mismatches; (2) It's not obvious which of the three methods is more accurate. Thank you; that is very helpful!

Re: a more precise distance algorithm

2015-05-25 Thread ravas
Oh ya... true >_< Thanks :D On Monday, May 25, 2015 at 9:43:47 PM UTC-7, Ian wrote: > > def distance(A, B): > > """ > > A & B are objects with x and y attributes > > :return: the distance between A and B > > """ > > dx = B.x - A.x > > dy = B.y - A.y > > a = min(dx, dy)

Re: a more precise distance algorithm

2015-05-25 Thread Ian Kelly
On Mon, May 25, 2015 at 1:21 PM, ravas wrote: > I read an interesting comment: > """ > The coolest thing I've ever discovered about Pythagorean's Theorem is an > alternate way to calculate it. If you write a program that uses the distance > form c = sqrt(a^2 + b^2) you will suffer from the lose

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 8:11:25 PM UTC-7, Steven D'Aprano wrote: > Let's compare three methods. > ... > which shows that: > > (1) It's not hard to find mismatches; > (2) It's not obvious which of the three methods is more accurate. Thank you; that is very helpful! I'm curious: what about the

Re: a more precise distance algorithm

2015-05-25 Thread Steven D'Aprano
On Tue, 26 May 2015 05:21 am, ravas wrote: > I read an interesting comment: > """ > The coolest thing I've ever discovered about Pythagorean's Theorem is an > alternate way to calculate it. If you write a program that uses the > distance form c = sqrt(a^2 + b^2) you will suffer from the lose of ha

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 1:27:43 PM UTC-7, Gary Herron wrote: > This is a statement about floating point numeric calculations on a > computer,. As such, it does apply to Python which uses the underlying > hardware for floating point calculations. > > Validity is another matter. Where did yo

Re: a more precise distance algorithm

2015-05-25 Thread ravas
On Monday, May 25, 2015 at 1:27:24 PM UTC-7, Christian Gollwitzer wrote: > Wrong. Just use the built-in function Math.hypot() - it should handle > these cases and also overflow, infinity etc. in the best possible way. > > Apfelkiste:~ chris$ python > Python 2.7.2 (default, Oct 11 2012, 20:14:37)

Re: a more precise distance algorithm

2015-05-25 Thread Christian Gollwitzer
Am 25.05.15 um 21:21 schrieb ravas: I read an interesting comment: """ The coolest thing I've ever discovered about Pythagorean's Theorem is an alternate way to calculate it. If you write a program that uses the distance form c = sqrt(a^2 + b^2) you will suffer from the lose of half of your av

Re: a more precise distance algorithm

2015-05-25 Thread Gary Herron
On 05/25/2015 12:21 PM, ravas wrote: I read an interesting comment: """ The coolest thing I've ever discovered about Pythagorean's Theorem is an alternate way to calculate it. If you write a program that uses the distance form c = sqrt(a^2 + b^2) you will suffer from the lose of half of your a

Re: a more precise distance algorithm

2015-05-25 Thread felix
El 25/05/15 15:21, ravas escribió: I read an interesting comment: """ The coolest thing I've ever discovered about Pythagorean's Theorem is an alternate way to calculate it. If you write a program that uses the distance form c = sqrt(a^2 + b^2) you will suffer from the lose of half of your ava

Re: A more general solution

2010-05-09 Thread Tim Chase
On 05/08/2010 10:33 PM, 3Jane wrote: You could interpret [[1,2,3,4],[5,6,7,8]] as a tree and your task as traversal of its leaves. All solutions before would not work with trees with bigger height. Here is how to traverse such trees recursively: def eventualPrint(x): for v in x: i

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
Dennis Lee Bieber wrote: On Sat, 27 Feb 2010 13:00:32 +1300, Gib Bogle declaimed the following in gmane.comp.python.general: The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, A

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not oc

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
The PyQt4 problem results from having copies of the Qt DLLs in directories that are in the PATH, as Doug Bell discovered. In my case I have two programs that use Qt, AMD CodeAnalyst and Matlab. If I rename BOTH these directories I can import the PyQt4 modules. Since this behaviour did not oc

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
The point of my question was that sys.path is clearly not being used in this case. When I start Python sys.path includes D:\python26\lib\site-packages which seems to be the Python default. Using sys.path.append I have tried adding both D:\python26\lib\site-packages\PyQt4 and D:\python26\lib\si

Re: A more specific query ...

2010-02-26 Thread Gib Bogle
Chris Rebert wrote: On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle wrote: How can I interrogate Python to find out where it is looking to find the PyQt4 DLLs in a Windows installation? import sys print(sys.path) Note this thread: http://www.mail-archive.com/p...@riverbankcomputing.com/msg20121

Re: A more specific query ...

2010-02-26 Thread Chris Rebert
On Fri, Feb 26, 2010 at 12:45 PM, Gib Bogle wrote: > How can I interrogate Python to find out where it is looking to find the > PyQt4 DLLs in a Windows installation? import sys print(sys.path) Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list

Re: A more pythonish code

2010-02-26 Thread prasad_chand
Hi Mr.Posner & nn, Thank your for your time & effort. I never knew that for...ever combination even existed. I would keep these insights in mind in the future. Thanks again, Prasad On Feb 25, 10:57 pm, John Posner wrote: > On 2/25/2010 7:23 AM, prasad_chand wrote: > > > > > Hi, > > > I use pyth

Re: A more pythonish code

2010-02-25 Thread nn
prasad_chand wrote: > Hi, > > I use python to do simple math problems as a hobby. > > I have made a program that finds the number of divisors(factors) of a > given number. I am hoping to improve my language skills, specifically > I would like to re-write the function "prime_factors" more graceful

Re: A More Concise Description of Numpy than the Guide to Numpy?

2009-11-23 Thread W. eWatson
Robert Kern wrote: On 2009-11-23 11:49 AM, W. eWatson wrote: I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_L

Re: A More Concise Description of Numpy than the Guide to Numpy?

2009-11-23 Thread Robert Kern
On 2009-11-23 11:49 AM, W. eWatson wrote: I'm looking the 300+ page pdf of the Guide to Numpy. Is there a more concise and practical guide to its use in science and mathematics? You will want to ask numpy questions on the numpy mailing list: http://www.scipy.org/Mailing_Lists You may also f

Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 6, 12:19 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote: > > I like to believe that the less the 'debug pointer' stands in the python > > code, the fastest the code is (or is potentially) > > What's a debug pointer? > > Pre-

Re: A more pythonic way of writting

2008-12-05 Thread Steven D'Aprano
On Fri, 05 Dec 2008 07:44:21 -0800, eric wrote: > I like to believe that the less the 'debug pointer' stands in the python > code, the fastest the code is (or is potentially) What's a debug pointer? Pre-mature optimization is the root of evil in programming. Unless you have actually *measured*

Re: A more pythonic way of writting

2008-12-05 Thread eric
On Dec 5, 3:44 pm, "Mark Tolonen" <[EMAIL PROTECTED]> wrote: > "eric" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, > > DOTALL=False, UNICODE=False, VERBOSE=False): > >    vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL

Re: A more pythonic way of writting

2008-12-05 Thread Gerard flanagan
eric wrote: Hi, I've got this two pieces of code that works together, and fine def testit(): for vals in [[i&mask==mask for mask in [1<', flag(*vals) def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, DOTALL=False, UNICODE=False, VERBOSE=False): vals = [IGNORECASE, LOCALE, MULT

Re: A more pythonic way of writting

2008-12-05 Thread Mark Tolonen
"eric" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] def flag(IGNORECASE=False, LOCALE=False, MULTILINE=False, DOTALL=False, UNICODE=False, VERBOSE=False): vals = [IGNORECASE, LOCALE, MULTILINE, DOTALL, UNICODE, VERBOSE] filtered = map( lambda m:m[1],filter( lambda m: m[0]

Re: A more navigable Python Library Reference page

2007-03-03 Thread [EMAIL PROTECTED]
> > Google doesn't seem to let you add attachments so I've put a sample of > the output here:http://www.qtrac.eu/libindex.html > at the bottom of the page there is a link to the ~100 line libindex.py > script that generated it. I like it. thanks. -- http://mail.python.org/mailman/listinfo/pyth

Re: A more elegant way to do this list comprehension?

2006-06-07 Thread [EMAIL PROTECTED]
> > [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, > > 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8] > [i+1 for i in range(8) for j in range(i+1)] [i for i in range(9) for j in range(i)] -- http://mail.python.org/mailman/listinfo/python-list

Re: A more elegant way to do this list comprehension?

2006-06-06 Thread Gary Herron
Levi Self wrote: > This probably seems very trivial, maybe even a bit silly, but I was > wondering if someone has a better list comprehension that does the > same thing as this one: > > >>> print [[[i]*i for i in range(1,9)][j][k] for j in range(8) for k > in range(j+1)] > [1, 2, 2, 3, 3, 3, 4, 4,

Re: a more precise re for email addys

2006-01-19 Thread rbt
[EMAIL PROTECTED] wrote: > Does it really need to be a regular expression? Why not just write a > short function that breaks apart the input and validates each part? > > def IsEmail(addr): > 'Returns True if addr appears to be a valid email address' > > # we don't allow stuff like [EMAIL PROT

Re: a more precise re for email addys

2006-01-18 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: > rbt> re.compile('([EMAIL PROTECTED])') > rbt> re.compile(r'[EMAIL PROTECTED],4}') > rbt> re.compile('(\S+)@(\S+)') > > rbt> All of these will find email addys, but they also find other > rbt> things. > > I think the only way to decide if your regular

Re: a more precise re for email addys

2006-01-18 Thread rbt
[EMAIL PROTECTED] wrote: > Does it really need to be a regular expression? Why not just write a > short function that breaks apart the input and validates each part? > > def IsEmail(addr): > 'Returns True if addr appears to be a valid email address' > > # we don't allow stuff like [EMAIL PROT

Re: a more precise re for email addys

2006-01-18 Thread dave . brueck
Does it really need to be a regular expression? Why not just write a short function that breaks apart the input and validates each part? def IsEmail(addr): 'Returns True if addr appears to be a valid email address' # we don't allow stuff like [EMAIL PROTECTED]@biff.com if addr.count('@') !=

Re: a more precise re for email addys

2006-01-18 Thread rbt
Jim wrote: > There is a precise one in a Perl module, I believe. > http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html > Can you swipe that? > > Jim > I can swipe it... but it causes my head to explode. I get unbalanced paratheses errors when trying to make it work as a python re... it mak

Re: a more precise re for email addys

2006-01-18 Thread André Malo
* rbt wrote: > Is it possible to write an re that _only_ matches email addresses? No. The only way to check if the matched thing is a mail address is to send a mail and ask the supposed receiver whether he got it. The grammar in RFC 2822 nearly matches anything with an @ in it. So, how accurate

Re: a more precise re for email addys

2006-01-18 Thread skip
Jim> http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html Maybe Cafe Express could be convinced to put that on a t-shirt... Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: a more precise re for email addys

2006-01-18 Thread skip
rbt> re.compile('([EMAIL PROTECTED])') rbt> re.compile(r'[EMAIL PROTECTED],4}') rbt> re.compile('(\S+)@(\S+)') rbt> All of these will find email addys, but they also find other rbt> things. I think the only way to decide if your regular expression does what you want is to pro

Re: a more precise re for email addys

2006-01-18 Thread Todd Whiteman
OMG, that is so ugly :D Jim wrote: > There is a precise one in a Perl module, I believe. > http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html > Can you swipe that? > > Jim > > -- http://mail.python.org/mailman/listinfo/python-list

Re: a more precise re for email addys

2006-01-18 Thread Jim
There is a precise one in a Perl module, I believe. http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html Can you swipe that? Jim -- http://mail.python.org/mailman/listinfo/python-list