Re: List comprehension timing difference.

2011-09-02 Thread Bart Kastermans
t...@thsu.org writes: > On Sep 2, 9:54 am, Bart Kastermans wrote: >> if d(a,b) == 1 and a < b: > > It will probably be faster if you reverse the evaluation order of that > expression. > > if a > That way the d() function is called less than half the time. Of course > this assumes that a that's tr

Re: List comprehension timing difference.

2011-09-02 Thread ting
On Sep 2, 9:54 am, Bart Kastermans wrote: > if d(a,b) == 1 and a < b: It will probably be faster if you reverse the evaluation order of that expression. if ahttp://mail.python.org/mailman/listinfo/python-list

Re: List comprehension timing difference.

2011-09-02 Thread Bart Kastermans
MRAB writes: > On 02/09/2011 01:35, Bart Kastermans wrote: >> graph = [[a,b] for a in data for b in data if d(a,b) ==1 and a< b] >> graph2 = [] >> for i in range (0, len(data)): >> for j in range(0,len(data)): >> if d(data[i],data[j]) == 1 and i< j: >> graph2.append

Re: List comprehension timing difference.

2011-09-01 Thread MRAB
On 02/09/2011 01:35, Bart Kastermans wrote: In the following code I create the graph with vertices sgb-words.txt (the file of 5 letter words from the stanford graphbase), and an edge if two words differ by one letter. The two methods I wrote seem to me to likely perform the same computations, t

List comprehension timing difference.

2011-09-01 Thread Bart Kastermans
In the following code I create the graph with vertices sgb-words.txt (the file of 5 letter words from the stanford graphbase), and an edge if two words differ by one letter. The two methods I wrote seem to me to likely perform the same computations, the list comprehension is faster though (281