how to append to a list twice?

John Salerno johnjsal at NOSPAMgmail.com
Fri Apr 21 16:00:20 EDT 2006


John Salerno wrote:
> callmebill at gmail.com wrote:
>> I don't get it (the Elliot solution)... How is it that the first value
>> is repeated once times, and the remaining values are repeated twice
>> times?
>>
> 
> Because of the way division works. The first number in the range is 200, 
> and 200/2 is 100. The next number is 199, and 199/2 is (as division 
> works right now) 99 (99.5 rounded). Next is 198, and that halved is also 
> 99 (this time with no remainder). Every two sets of numbers thereafter 
> also do the same.

I should also say, to answer your question more directly, that the 
reason it doesn't happen to the first number is because it only works on 
an odd number and the number below it, i.e. 199 and 198 both yield 99. 
If our range had started with 201, then 100 would have been repeated twice.



More information about the Python-list mailing list