a simple 'else' decrease speed by 1000 times.

Chris Liechti cliechti at gmx.net
Sat Mar 2 10:00:48 EST 2002


husam <h.jehadalwan at student.kun.nl> wrote in news:3C80E535.7000407
@student.kun.nl:

> Chris Liechti wrote:
> 
>> husam <h.jehadalwan at student.kun.nl> wrote in news:3C80BBAC.2060600
>> @student.kun.nl: 
>> 
>>>One else statement decrease speed by 1000 times. Why is that?
>>>
>> ...
>> 
>>>                           if prv == n[i][-1]: n[i].append(new)
>>>                                print count, '\t', i , '\t',n[i]
>>>                                count = count +1 break else:
>>>                              n[i].append(0) 
>>>
>> 
>> 'cause your not "break"-ing here? but you do in the "if-then" 
part...
> 
> 
> It should not break here. Because imagin that the matching 'prv' is 
> somewhere in a line in the middle of the file, the code will break 
> immediately at the first non-matching line.

yes, you're right but that means that the else part is executen many 
times and that will slow down your program. 

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list