Re: math - need divisors algorithm

2005-04-05 Thread David Eppstein
t/egypt.py> (look for the function called, surprisingly, "divisors"). It's not very compact -- 155 lines from the start of the Pollard Rho factorization (thanks to Kirby Urner) to the end of the divisors function, but it's reasonably efficient even for largish numbers. --

Re: itertools to iter transition (WAS: Pre-PEP: Dictionary accumulator methods)

2005-03-28 Thread David Eppstein
hat happens with any class name) iter(x) is almost never going to return an object of that type. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread David Eppstein
here several times, of changing the dict's behavior so that the setdefault is automatic whenever trying to access a missing key. If this would be in a separate module or separate subclass of dict, so much the better. -- David Eppstein Computer Science Dept., Univ. of California, Irvine

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread David Eppstein
In article <[EMAIL PROTECTED]>, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote: > Also, in all of my code base, I've not run across a single opportunity to use > something like unionset(). In my code, this would be roughly tied with appendlist for frequency of

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread David Eppstein
but if you were to take that minimalist philosophy to an extreme you wouldn't need count either, you could just appendlist then use len. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: a program to delete duplicate files

2005-03-14 Thread David Eppstein
t sure what the trade off between disk seeks and disk reads > does to the problem, in practice (with caching and realistic memory > constraints). Another interesting point. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: a program to delete duplicate files

2005-03-14 Thread David Eppstein
suming very strong cryptographic hashes, good enough that you can trust equal results to really be equal without having to verify by a comparison. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: a program to delete duplicate files

2005-03-14 Thread David Eppstein
s 2(m-1) reads and very little computation better than m reads and a strong hash computation? I haven't yet seen an answer to this, but it's a question for experimentation rather than theory. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] a program to delete duplicate files

2005-03-11 Thread David Eppstein
're doing any comparisons at all, you're not minimizing the number of comparisons. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] a program to delete duplicate files

2005-03-11 Thread David Eppstein
of the files exist in only one copy, it's clear that the cheap hash will find them more cheaply than the expensive hash. In that case you could combine the (file size, cheap hash) filtering with the expensive hash and get only two reads per copy rather than three. -- David Eppstein Comput

Re: [perl-python] a program to delete duplicate files

2005-03-10 Thread David Eppstein
strong hash algorithm (SHA-256 maybe?) and compare the hashes. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: yield_all needed in Python

2005-03-01 Thread David Eppstein
ple generators could have yield_all's to the same iterator) but I think it could be made nearly constant time in most situations. On the other hand, I'm not convinced that this would be needed frequently enough to warrant the complexity of trying to optimize it. -- David Epps

Re: [perl-python] generic equivalence partition

2005-02-24 Thread David Eppstein
In article <[EMAIL PROTECTED]>, David Eppstein <[EMAIL PROTECTED]> wrote: > def parti(aList,equalFunc): > eqv = [] > for i in range(len(aList)): > print i,eqv > for L in eqv: > if equalFunc(aList[i],aList[L[0]])

Re: [perl-python] generic equivalence partition

2005-02-24 Thread David Eppstein
eqv.append([i]) If you really want the ranges to be 1 to n, add one to each number in the returned list-of-lists. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: exercise: partition a list by equivalence

2005-02-22 Thread David Eppstein
-working > versions from SIX people: Reinhold, bear.+, Brian Beck, David Eppstein, > yourself, and me. Only David's uses stuff that's not in the Python 2.4 > off-the-shelf distribution. Where "stuff" means a single 62-line file that I linked to in my post. -

Re: exercise: partition a list by equivalence

2005-02-19 Thread David Eppstein
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > David Eppstein: > > However it might be easier to treat the input pairs as the edges of a > > graph and apply a depth-first-search based graph connected components > > algorithm. || This would be O(n), thoug

Re: exercise: partition a list by equivalence

2005-02-18 Thread David Eppstein
In article <[EMAIL PROTECTED]>, David Eppstein <[EMAIL PROTECTED]> wrote: > It can be solved by union-find > (e.g. with UnionFind from <http://www.ics.uci.edu/~eppstein/PADS/>): Here's a cleaned up version, after I added a proper iter() method to the UnionFind data

Re: exercise: partition a list by equivalence

2005-02-18 Thread David Eppstein
ns before all the finds, as in this algorithm, union-find is O(n). However it might be easier to treat the input pairs as the edges of a graph and apply a depth-first-search based graph connected components algorithm. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.i

Re: Why doesn't join() call str() on its arguments?

2005-02-16 Thread David Eppstein
r e.g. > user-defined classes that have a __str__() defined. That would be the wrong thing to do when the arguments are unicodes. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] combinatorics fun

2005-02-10 Thread David Eppstein
'2,4': (2, 4), '3,4': (3, 4)} Note I'm using 0-based indexing, use range(1,n+1) and range(1,j+1) instead if you really need it to be 1-based. Also I'm using Python 2.3, I think in 2.4 you can take out the square brackets and it would still work. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary keys (again) (was Re: lambda)

2005-01-19 Thread David Eppstein
[lst] > > Should print: > Hi > Hi > Hi > Hi Yes, and what should the following do? lst1 = [1] lst2 = [2] dct = {lst1: "1", lst2: "2"} lst2[0]=1 lst1[0]=2 print dct[[1]] print dct[[2]] -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list

Re: guarding for StopIteration (WAS: Help with generators outside of loops.)

2004-12-08 Thread David Eppstein
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> wrote: > David Eppstein wrote: > > I've made it a policy in my own code to always surround explicit calls > > to next() with try ... except StopIteration ... guards. > > > > Otherwis

Re: Help with generators outside of loops.

2004-12-08 Thread David Eppstein
her back in the call chain is looking for StopIteration. Which could be the case if the call chain includes a for-loop that is calling the next() method of another generator. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.p

Re: Help with generators outside of loops.

2004-12-07 Thread David Eppstein
l terminate without any error messages and the cause of its termination can be very difficult to track down. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/ -- http://mail.python.org/mailman/listinfo/python-list