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.
--
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
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
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
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
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
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
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 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
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
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
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
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]])
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
-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.
-
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
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
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
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
'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
[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
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
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
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
24 matches
Mail list logo