Re: How safe is a set of floats?

2007-05-09 Thread Dave Borne
On 4 May 2007 07:21:49 -0700, Thomas Nelson <[EMAIL PROTECTED]> wrote: > I want to generate all the fractions between 1 and limit (with > limit>1) in an orderly fashion, without duplicates. Might I suggest the Stern-Brocot tree (http://en.wikipedia.org/wiki/Stern-Brocot_tree) It will eliminate the

Re: How safe is a set of floats?

2007-05-08 Thread Klaas
On May 4, 10:15 am, Paul McGuire <[EMAIL PROTECTED]> wrote: > Just to beat this into the ground, "test for equality" appears to be > implemented as "test for equality of hashes". So if you want to > implement a class for the purposes of set membership, you must > implement a suitable __hash__ met

Re: How safe is a set of floats?

2007-05-04 Thread Peter Otten
Paul McGuire wrote: > Just to beat this into the ground, "test for equality" appears to be > implemented as "test for equality of hashes". So if you want to > implement a class for the purposes of set membership, you must > implement a suitable __hash__ method. It is not sufficient to > implemen

Re: How safe is a set of floats?

2007-05-04 Thread Paul McGuire
On May 4, 11:50 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > On May 4, 5:04 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > > > Does set membership test for equality ("==") or identity ("is")? I > > just did some simple class tests, and it looks like sets test for > > identity. > > Sets are lik

Re: How safe is a set of floats?

2007-05-04 Thread Arnaud Delobelle
On May 4, 5:04 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > Does set membership test for equality ("==") or identity ("is")? I > just did some simple class tests, and it looks like sets test for > identity. Sets are like dictionaries, they test for equality: >>> a=1,2 >>> b=1,2 >>> a is b False

Re: How safe is a set of floats?

2007-05-04 Thread Peter Otten
Paul McGuire wrote: > Does set membership test for equality ("==") or identity ("is")? As Alex said, equality: >>> a = 0.0 >>> b = -0.0 >>> a is b False >>> a == b True >>> set([a, b]) set([0.0]) Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: How safe is a set of floats?

2007-05-04 Thread Arnaud Delobelle
On May 4, 3:21 pm, Thomas Nelson <[EMAIL PROTECTED]> wrote: > I want to generate all the fractions between 1 and limit (with > limit>1) in an orderly fashion, without duplicates. > > def all_ratios(limit): > s = set() > hi = 1.0 > lo = 1.0 > while True: > if hi/lo not in s:

Re: How safe is a set of floats?

2007-05-04 Thread Paul McGuire
On May 4, 9:50 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > Thomas Nelson <[EMAIL PROTECTED]> wrote: > > I want to generate all the fractions between 1 and limit (with > > limit>1) in an orderly fashion, without duplicates. > > > def all_ratios(limit): > > s = set() > > hi = 1.0 > > l

Re: How safe is a set of floats?

2007-05-04 Thread Alex Martelli
Thomas Nelson <[EMAIL PROTECTED]> wrote: > I want to generate all the fractions between 1 and limit (with > limit>1) in an orderly fashion, without duplicates. > > def all_ratios(limit): > s = set() > hi = 1.0 > lo = 1.0 > while True: > if hi/lo not in s: > s.a

How safe is a set of floats?

2007-05-04 Thread Thomas Nelson
I want to generate all the fractions between 1 and limit (with limit>1) in an orderly fashion, without duplicates. def all_ratios(limit): s = set() hi = 1.0 lo = 1.0 while True: if hi/lo not in s: s.add(hi/lo) yield (hi,lo) hi += 1 if