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
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
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
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
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
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
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:
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
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
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
10 matches
Mail list logo