Re: For loop searching takes too long!

2010-02-02 Thread Jonathan Gardner
On Jan 29, 7:07 pm, Steven D'Aprano wrote: > On Fri, 29 Jan 2010 14:49:06 -0800, Jonathan Gardner wrote: > > On Jan 28, 3:52 pm, elsa wrote: > > >> I've got a problem with my program, in that the code just takes too > >> long to run. Here's what I'm doing. If anyone has any tips, they'd be > >> m

Re: For loop searching takes too long!

2010-02-01 Thread Steven D'Aprano
On Mon, 01 Feb 2010 14:04:01 -0800, Jonathan Gardner wrote: > Having worked with datasets that are truly enormous, whenever I see a > list that is unbounded (as this appears to be), I freak out because > unbounded can be a really, really big number. Might as well write > software that works for th

Re: For loop searching takes too long!

2010-01-29 Thread Steven D'Aprano
On Fri, 29 Jan 2010 14:49:06 -0800, Jonathan Gardner wrote: > On Jan 28, 3:52 pm, elsa wrote: >> >> I've got a problem with my program, in that the code just takes too >> long to run. Here's what I'm doing. If anyone has any tips, they'd be >> much appreciated! >> >> > First of all, don't play wi

Re: For loop searching takes too long!

2010-01-29 Thread Jonathan Gardner
On Jan 28, 3:52 pm, elsa wrote: > > I've got a problem with my program, in that the code just takes too > long to run. Here's what I'm doing. If anyone has any tips, they'd be > much appreciated! > First of all, don't play with large lists. Large lists have a tendency to grow larger over time, un

Re: For loop searching takes too long!

2010-01-28 Thread Daniel Stutzbach
On Thu, Jan 28, 2010 at 5:52 PM, elsa wrote: >choice = random.choice(range(1,sum([i[0] for i in myList])+1)) > That's the line causing the problem. It's generating all of the numbers between 1 and your sum, then picking one. Try the following instead, which will pick a number between 1

Re: For loop searching takes too long!

2010-01-28 Thread Dave Angel
Steve Holden wrote: Dave Angel wrote: elsa wrote: Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks something like this (I'm usi

Re: For loop searching takes too long!

2010-01-28 Thread Steve Holden
Steve Holden wrote: > Dave Angel wrote: >> elsa wrote: >>> Hi guys, >>> >>> I've got a problem with my program, in that the code just takes too >>> long to run. Here's what I'm doing. If anyone has any tips, they'd be >>> much appreciated! >>> >>> So, say I have a list of lists that looks something

Re: For loop searching takes too long!

2010-01-28 Thread Steve Holden
Dave Angel wrote: > elsa wrote: >> Hi guys, >> >> I've got a problem with my program, in that the code just takes too >> long to run. Here's what I'm doing. If anyone has any tips, they'd be >> much appreciated! >> >> So, say I have a list of lists that looks something like this (I'm >> using a lis

Re: For loop searching takes too long!

2010-01-28 Thread Chris Colbert
if you're open to other libraries, this could be done extremely fast in numpy. On my machine summing that whole array takes 75ms. On Thu, Jan 28, 2010 at 8:00 PM, Steven D'Aprano < st...@remove-this-cybersource.com.au> wrote: > On Thu, 28 Jan 2010 15:52:14 -0800, elsa wrote: > > > Now, what I ne

Re: For loop searching takes too long!

2010-01-28 Thread Dave Angel
elsa wrote: Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks something like this (I'm using a list of lists, rather than a list of tuples

Re: For loop searching takes too long!

2010-01-28 Thread Steven D'Aprano
On Thu, 28 Jan 2010 15:52:14 -0800, elsa wrote: > Now, what I need to do is randomly choose one myList[i], however the > distribution of my random choice needs to be proportional to the values > of myList[i][0]. So, for this list above, I'd have a much higher chance > of choosing myList[0] than my

Re: For loop searching takes too long!

2010-01-28 Thread John Posner
On 1/28/2010 6:52 PM, elsa wrote: Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks something like this (I'm using a list of lists, rather

Re: For loop searching takes too long!

2010-01-28 Thread Peter Otten
elsa wrote: > Hi guys, > > I've got a problem with my program, in that the code just takes too > long to run. Here's what I'm doing. If anyone has any tips, they'd be > much appreciated! > > So, say I have a list of lists that looks something like this (I'm > using a list of lists, rather than a

For loop searching takes too long!

2010-01-28 Thread elsa
Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks something like this (I'm using a list of lists, rather than a list of tuples, as I need it