[beginner] What's wrong?

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Apr 8 19:07:08 EDT 2016


On 08/04/2016 23:59, sohcahtoa82 at gmail.com wrote:
> On Friday, April 1, 2016 at 3:57:40 PM UTC-7, Mark Lawrence wrote:
>> On 01/04/2016 23:44, sohcahtoa82 at gmail.com wrote:
>>> On Friday, April 1, 2016 at 3:10:51 PM UTC-7, Michael Okuntsov wrote:
>>>> Nevermind. for j in range(1,8) should be for j in range(8).
>>>
>>> I can't tell you how many times I've gotten bit in the ass with that off-by-one mistake whenever I use a range that doesn't start at zero.
>>>
>>> I know that if I want to loop 10 times and I either want to start at zero or just don't care about the actual number, I use `for i in range(10)`.  But if I want to loop from 10 to 20, my first instinct is to write `for i in range(10, 20)`, and then I'm left figuring out why my loop isn't executing the last step.
>>>
>>
>> "First instinct"?  "I expected"?  The Python docs might not be perfect,
>> but they were certainly adequate enough to get me going 15 years ago,
>> and since then they've improved.  So where is the problem, other than
>> failure to RTFM?
>>
>> --
>> My fellow Pythonistas, ask not what our language can do for you, ask
>> what you can do for our language.
>>
>> Mark Lawrence
>
> Holy hell, why such an aggressive tone?
>
> I understand how range(x, y) works.  It's just a simple mistake that I frequently do it wrong and have to correct it after the first time I run it.  It's not like I'm saying that the implementation needs to change.  I'm just saying that if I want to loop from 10 to 20, my first thought is to use range(10, 20).  It is slightly unintuitive.
>
> *YES*, I know it is wrong.  *YES*, I understand why the correct usage would be range(10, 21) to get that list from 10 to 20.
>
> Get off your high horse.  Not everybody is like you and has been using Python for 15 years and apparently never makes mistakes.
>

*plonk*

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list