Re: Simple algorithm question - how to reorder a sequence economically

2013-06-12 Thread Robert Kern
On 2013-05-24 14:43, Chris Angelico wrote: On Fri, May 24, 2013 at 11:23 PM, Peter Brooks wrote: Actually, thinking about it, there is probably a source of non-algorithmically-derived 'random' numbers somewhere on the net that would do the job nicely. True entropy is usually provided by a sou

RE: Simple algorithm question - how to reorder a sequence economically

2013-06-12 Thread Carlos Nepomuceno
> Date: Fri, 24 May 2013 17:28:07 -0700 > Subject: Re: Simple algorithm question - how to reorder a sequence > economically > From: peter.h.m.bro...@gmail.com > To: python-list@python.org [...] > If the scenario could be modelled ma

Re: Simple algorithm question - how to reorder a sequence economically

2013-06-12 Thread Chris Angelico
On Fri, May 24, 2013 at 11:23 PM, Peter Brooks wrote: > Actually, thinking about > it, there is probably a source of non-algorithmically-derived 'random' > numbers somewhere on the net that would do the job nicely. True entropy is usually provided by a source such as /dev/random (on Unix systems)

Re: Simple algorithm question - how to reorder a sequence economically

2013-06-12 Thread Dave Angel
On 05/25/2013 09:49 PM, Roy Smith wrote: In article <15a1bb3a-514c-454e-a966-243c84123...@googlegroups.com>, John Ladasky wrote: Because someone's got to say it... "The generation of random numbers is too important to be left to chance." ‹ Robert R. Coveyou Absolutely. I know just enough

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-25 Thread Roy Smith
In article <15a1bb3a-514c-454e-a966-243c84123...@googlegroups.com>, John Ladasky wrote: > Because someone's got to say it... "The generation of random numbers is too > important to be left to chance." ‹ Robert R. Coveyou Absolutely. I know just enough about random number generation to unders

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-25 Thread John Ladasky
On Friday, May 24, 2013 10:33:47 AM UTC-7, Yours Truly wrote: > If you don't reshuffle p, it guarantees the maximum interval between reusing > the same permutation. Of course, that comes at a certain price. Given two permutations p[x] and p[x+1], they will ALWAYS be adjacent, in every repetition

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
On May 24, 11:33 pm, Carlos Nepomuceno wrote: > > > > > > > > > > > > Date: Fri, 24 May 2013 12:01:35 -0700 > > Subject: Re: Simple algorithm question - how to reorder a sequence > > economically >

RE: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Carlos Nepomuceno
> Date: Fri, 24 May 2013 12:01:35 -0700 > Subject: Re: Simple algorithm question - how to reorder a sequence > economically > From: peter.h.m.bro...@gmail.com > To: python-list@python.org > > On May 24, 5:00 pm, Carlos Nepomuceno >

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
On May 24, 5:00 pm, Carlos Nepomuceno wrote: > > > I don't know what "spurious evidence of correlation" is. Can you give a > mathematical definition? > If I run the simulation with the same sequence, then, because event E1 always comes before event E2, somebody might believe that there is a causa

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread John Ladasky
On Friday, May 24, 2013 3:52:18 AM UTC-7, Steven D'Aprano wrote: > On Fri, 24 May 2013 01:14:45 -0700, Peter Brooks wrote: > > > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg > > 2,1,4,3) that is different each time. > > You can't *guarantee* that it will be different each

RE: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Carlos Nepomuceno
> Date: Fri, 24 May 2013 01:14:45 -0700 > Subject: Simple algorithm question - how to reorder a sequence economically > From: peter.h.m.bro...@gmail.com > To: python-list@python.org > > What is the easiest way to reorder a sequence pseudo-

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread duncan smith
On 24/05/13 10:11, Chris Angelico wrote: On Fri, May 24, 2013 at 6:47 PM, Fábio Santos wrote: On 24 May 2013 09:41, "Chris Angelico" wrote: On Fri, May 24, 2013 at 6:14 PM, Peter Brooks wrote: What is the easiest way to reorder a sequence pseudo-randomly? That is, for a sequence 1,2,3,4

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Steven D'Aprano
On Fri, 24 May 2013 06:23:14 -0700, Peter Brooks wrote: > Thanks for the warnings about random numbers too - I hope my lists will > be short enough for the permutations of the function to be irrelevant. I > don't need every single sequence to be unique, only that the same > sequence only occurs o

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
Thank you all for those most helpful suggestions! random.shuffle does precisely the job that I need quickly. Thank you for introducing me to itertools, though, I should have remembered APL did this in a symbol or two and I'm sure that itertools will come in handy in future. Thanks for the warnings

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Ned Batchelder
On 5/24/2013 6:52 AM, Steven D'Aprano wrote: On Fri, 24 May 2013 01:14:45 -0700, Peter Brooks wrote: What is the easiest way to reorder a sequence pseudo-randomly? import random random.shuffle(sequence) The sequence is modified in place, so it must be mutable. Lists are okay, tuples are not.

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Steven D'Aprano
On Fri, 24 May 2013 01:14:45 -0700, Peter Brooks wrote: > What is the easiest way to reorder a sequence pseudo-randomly? import random random.shuffle(sequence) The sequence is modified in place, so it must be mutable. Lists are okay, tuples are not. > That is, for a sequence 1,2,3,4 to produ

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Terry Jan Reedy
On 5/24/2013 4:14 AM, Peter Brooks wrote: What is the easiest way to reorder a sequence pseudo-randomly? That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg 2,1,4,3) that is different each time. I'm writing a simulation and would like to visit all the nodes in a different order

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 6:47 PM, Fábio Santos wrote: > > On 24 May 2013 09:41, "Chris Angelico" wrote: >> >> On Fri, May 24, 2013 at 6:14 PM, Peter Brooks >> wrote: >> > What is the easiest way to reorder a sequence pseudo-randomly? >> > >> > That is, for a sequence 1,2,3,4 to produce an arbitra

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Fábio Santos
On 24 May 2013 09:41, "Chris Angelico" wrote: > > On Fri, May 24, 2013 at 6:14 PM, Peter Brooks > wrote: > > What is the easiest way to reorder a sequence pseudo-randomly? > > > > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg > > 2,1,4,3) that is different each time. > > ..

Re: Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 6:14 PM, Peter Brooks wrote: > What is the easiest way to reorder a sequence pseudo-randomly? > > That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg > 2,1,4,3) that is different each time. > > I'm writing a simulation and would like to visit all the nodes

Simple algorithm question - how to reorder a sequence economically

2013-05-24 Thread Peter Brooks
What is the easiest way to reorder a sequence pseudo-randomly? That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg 2,1,4,3) that is different each time. I'm writing a simulation and would like to visit all the nodes in a different order at each iteration of the simulation to remo

Re: Python Dictionary Algorithm Question

2008-12-16 Thread Steve Holden
Brigette Hodson wrote: > Hello! I am in a beginning algorithms class this semester and I am > working on a presentation. I want to discuss in some detail the > algorithm python uses to determine the hash function for python > dictionaries. Does anyone know what this algorithm is? Or where I can go

Re: Python Dictionary Algorithm Question

2008-12-16 Thread Scott MacDonald
You might be interested in the "Beautiful Code" book: http://oreilly.com/catalog/9780596510046/ It has a chapter on Python's dict implementation that is pretty good. On Tue, Dec 16, 2008 at 10:51 AM, Brigette Hodson wrote: > Hello! I am in a beginning algorithms class this semester and I am work

Re: Python Dictionary Algorithm Question

2008-12-16 Thread Christian Heimes
Brigette Hodson schrieb: > Hello! I am in a beginning algorithms class this semester and I am working > on a presentation. I want to discuss in some detail the algorithm python > uses to determine the hash function for python dictionaries. Does anyone > know what this algorithm is? Or where I can g

Python Dictionary Algorithm Question

2008-12-16 Thread Brigette Hodson
Hello! I am in a beginning algorithms class this semester and I am working on a presentation. I want to discuss in some detail the algorithm python uses to determine the hash function for python dictionaries. Does anyone know what this algorithm is? Or where I can go to find information on it? Tha

Re: Algorithm Question

2006-09-26 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Andrew McLean wrote: > I have the ability to query a database in a legacy system and extract > records which match a particular pattern. Specifically, I can perform > queries for records that contain a given search term as a sub-string of > a particular column. Wha

Re: Algorithm Question

2006-09-14 Thread George Sakkis
Gabriel Genellina wrote: > This is known as a "set cover" algorithm. You have a set of subsets, > and want to determine the smallest set of those subsets, whose union > is the universal set - (uh, what a mess!) I thought of that too, but he seems to be adding a second desired property: the inters

Re: Algorithm Question

2006-09-14 Thread Gabriel Genellina
At Thursday 14/9/2006 20:31, Andrew McLean wrote: Now I want to issue a series of queries, such that when I combine all the data returned I have accessed all the records in the database. However, I want to minimise the total number of queries and also want to keep the number of records returned

Re: Algorithm Question

2006-09-14 Thread George Sakkis
Andrew McLean wrote: > Now I want to issue a series of queries, such that when I combine all > the data returned I have accessed all the records in the database. > However, I want to minimise the total number of queries and also want to > keep the number of records returned by more than one query

Re: Algorithm Question

2006-09-14 Thread Andrew McLean
John Machin wrote: > A quick silly question: what is the problem that you are trying to > solve? A fair question :-) The problem may seem a bit strange, but here it is: I have the ability to query a database in a legacy system and extract records which match a particular pattern. Specifically,

Re: Algorithm Question

2006-09-11 Thread John Machin
Andrew McLean wrote: > Carl Banks wrote: > > Andrew McLean wrote: > >> I have a list of strings, A. I want to find a set of strings B such that > >> for any "a in A" there exists "b in B" such that b is a sub-string of a. > > > > B=A? > > > >> But I also want to minimise T = sum_j t_j where > >> t

Re: Algorithm Question

2006-09-11 Thread Andrew McLean
Carl Banks wrote: > Andrew McLean wrote: >> I have a list of strings, A. I want to find a set of strings B such that >> for any "a in A" there exists "b in B" such that b is a sub-string of a. > > B=A? > >> But I also want to minimise T = sum_j t_j where >> t_j = count of the number of elements i

Re: Algorithm Question

2006-09-11 Thread Carl Banks
Andrew McLean wrote: > I have a list of strings, A. I want to find a set of strings B such that > for any "a in A" there exists "b in B" such that b is a sub-string of a. B=A? > But I also want to minimise T = sum_j t_j where > t_j = count of the number of elements in A which have b[j] as a sub-s

Re: Algorithm Question

2006-09-11 Thread Neil Cerutti
On 2006-09-10, Andrew McLean <[EMAIL PROTECTED]> wrote: > This really an algorithm question more that a Python question, > but it would be implemented in Python In that case, try comp.programming. But still... > I have a list of strings, A. I want to find a set of strings B

Algorithm Question

2006-09-10 Thread Andrew McLean
This really an algorithm question more that a Python question, but it would be implemented in Python I have a list of strings, A. I want to find a set of strings B such that for any "a in A" there exists "b in B" such that b is a sub-string of a. But I also want to mi

Re: fast pythonic algorithm question

2006-08-01 Thread Guyon Morée
Brian you are right, but in my case (host, port, protocol) is unique. [EMAIL PROTECTED] schreef: > Guyon Morée wrote: > > i have a big list of tuples like this: > > > > [ (host, port, protocol, startime, endtime), .. ] etc > > > > now i have another big(ger) list of tuples like this: > > > > [(s

Re: fast pythonic algorithm question

2006-08-01 Thread bryanjugglercryptographer
Guyon Morée wrote: > i have a big list of tuples like this: > > [ (host, port, protocol, startime, endtime), .. ] etc > > now i have another big(ger) list of tuples like this: > > [(src_host, src_port, dest_src, dest_port, protocol, time), ... ] etc > > now i need to find all the items in the seco

Re: fast pythonic algorithm question

2006-08-01 Thread Diez B. Roggisch
>> I'd say it is as fast as it can get - using hashing for lookups is O >> (n) in > > > I know you meant O(1) for hash lookups, but just in case anyone is > confused, I figured I'd correct this. Ooops. Thanks. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: fast pythonic algorithm question

2006-08-01 Thread David Reed
On Aug 1, 2006, at 11:13 AM, Diez B. Roggisch wrote: > Guyon Morée wrote: > >> Memory is no problem. It just needs to be as fast as possible, if >> that's what this is, fine. >> >> If not, I'd like to find out what is :) > > I'd say it is as fast as it can get - using hashing for lookups is O >

Re: fast pythonic algorithm question

2006-08-01 Thread Diez B. Roggisch
Guyon Morée wrote: > Memory is no problem. It just needs to be as fast as possible, if > that's what this is, fine. > > If not, I'd like to find out what is :) I'd say it is as fast as it can get - using hashing for lookups is O(n) in most cases, where bisection or other order-based lookups have

Re: fast pythonic algorithm question

2006-08-01 Thread Guyon Morée
Memory is no problem. It just needs to be as fast as possible, if that's what this is, fine. If not, I'd like to find out what is :) thanx, Guyon Moree http://gumuz.looze.net Paul Rubin schreef: > "Guyon Morée" <[EMAIL PROTECTED]> writes: > > if (((src_host,src_port, protocol) in dict or (de

Re: fast pythonic algorithm question

2006-08-01 Thread Paul Rubin
"Guyon Morée" <[EMAIL PROTECTED]> writes: > if (((src_host,src_port, protocol) in dict or (dest_host, dest_port, > protocol) in dict) and starttime < time < endtime): > print "we have a winner" If you have enough memory to do it that way, what's the problem? -- http://mail.python.org/mailman/li

fast pythonic algorithm question

2006-08-01 Thread Guyon Morée
hi all, i have a big list of tuples like this: [ (host, port, protocol, startime, endtime), .. ] etc now i have another big(ger) list of tuples like this: [(src_host, src_port, dest_src, dest_port, protocol, time), ... ] etc now i need to find all the items in the second list where either src_