Prev: Is there any way to minimize str()/unicode() objects memory usage[Python 2.6.4] ?
Next: sched() function questions
From: Roald de Vries on 7 Aug 2010 11:38 On Aug 7, 2010, at 5:24 PM, Nobody wrote: > On Sat, 07 Aug 2010 13:48:32 +0200, News123 wrote: > >>> "Common sense" is wrong. There are many compelling advantages to >>> numbering from zero instead of one: >>> >>> http://lambda-the-ultimate.org/node/1950 >> >> It makes sense in assembly language and even in many byte code >> languages. >> It makes sense if you look at the internal representation of unsigned >> numbers (which might become an index) > > It also makes sense mathematically. E.g. for an MxN array stored as a > 1-dimensional array, the element a[j][i] is at index > > j * N + i Nice example!
From: John Nagle on 7 Aug 2010 15:14 On 8/7/2010 5:00 AM, Thomas Jollans wrote: > On 08/07/2010 05:05 AM, Default User wrote: >> > From "the emperor's new clothes" department: >> >> 1) Why do Python lists start with element [0], instead of element [1]? >> "Common sense" would seem to suggest that lists should start with [1]. > > As others have pointed out, there is a nice argument to be made for > zero-based indices. However, the killer reason is: "it's what everybody > else does." FORTRAN, MATLAB, and Octave all use 1-based subscripts. The languages which have real multidimensional arrays, rather than arrays of arrays, tend to use 1-based subscripts. That reflects standard practice in mathematics. John Nagle
From: rantingrick on 7 Aug 2010 18:02 On Aug 7, 9:10 am, Steven D'Aprano <st...(a)REMOVE-THIS- cybersource.com.au> wrote: > On Sat, 07 Aug 2010 08:54:28 -0400, D'Arcy J.M. Cain wrote: > > On Sat, 07 Aug 2010 13:48:32 +0200 > > News123 <news1...(a)free.fr> wrote: > >> It makes sense in assembly language and even in many byte code > >> languages. It makes sense if you look at the internal representation of > >> unsigned numbers (which might become an index) > > >> For a complete beginner common sense dictates differently and there > >> might be confusion why the second element in a list has index 1. > > > Would said beginner also be surprised that a newborn baby is zero years > > old or would it be more natural to call them a one year old? Zero based > > counting is perfectly natural. > > There's nothing natural about saying that a baby is zero years old. A > newborn baby is "a newborn baby", then it's "one day old", "two days > old", ... "one month old", "two months old", ... "one year old". Well not if you are referring to how people "say" things. But what people "say" and the facts of reality are some times two different things. Heck we even have a few folks in this group who overuse the expression "used to" quite frequently in place of the more correct term "previously" -- i won't give names. But if i did i would start at index zero! When any object is "born" (whether it be a life form, or a planet, or even a class instance) "it" will be zero years old until 1 year of time has passed has passed. If you want to properly describe age you could say a baby who was born five minutes ago is... - 0 millenniums - 0 centuries - 0 decades - 0 years - 0 months - 0 days - 0 hours - 5 minutes - 60*5 seconds - (60*5)*1000 millisecond - crikey i'm tired! Just because Aunt Martha is is too lazy to list out the details that has no effect on reality. YES a newborn is zero years old. YES, a newborn is zero months old, ...an so on.
From: MRAB on 7 Aug 2010 18:44 rantingrick wrote: > On Aug 7, 9:10 am, Steven D'Aprano <st...(a)REMOVE-THIS- > cybersource.com.au> wrote: >> On Sat, 07 Aug 2010 08:54:28 -0400, D'Arcy J.M. Cain wrote: >>> On Sat, 07 Aug 2010 13:48:32 +0200 >>> News123 <news1...(a)free.fr> wrote: >>>> It makes sense in assembly language and even in many byte code >>>> languages. It makes sense if you look at the internal representation of >>>> unsigned numbers (which might become an index) >>>> For a complete beginner common sense dictates differently and there >>>> might be confusion why the second element in a list has index 1. >>> Would said beginner also be surprised that a newborn baby is zero years >>> old or would it be more natural to call them a one year old? Zero based >>> counting is perfectly natural. >> There's nothing natural about saying that a baby is zero years old. A >> newborn baby is "a newborn baby", then it's "one day old", "two days >> old", ... "one month old", "two months old", ... "one year old". > > Well not if you are referring to how people "say" things. But what > people "say" and the facts of reality are some times two different > things. Heck we even have a few folks in this group who overuse the > expression "used to" quite frequently in place of the more correct > term "previously" -- i won't give names. But if i did i would start at > index zero! > There's nothing wrong with "used to", but "more correct"? It either _is_ correct or _isn't_ correct. And it's "I", not "i". :-) > When any object is "born" (whether it be a life form, or a planet, or > even a class instance) "it" will be zero years old until 1 year of > time has passed has passed. If you want to properly describe age you > could say a baby who was born five minutes ago is... > > - 0 millenniums millennia > - 0 centuries > - 0 decades > - 0 years > - 0 months > - 0 days > - 0 hours > - 5 minutes > - 60*5 seconds > - (60*5)*1000 millisecond > - crikey i'm tired! > > Just because Aunt Martha is is too lazy to list out the details that > has no effect on reality. YES a newborn is zero years old. YES, a > newborn is zero months old, ...an so on.
From: Ben Finney on 7 Aug 2010 19:34
Steven D'Aprano <steve(a)REMOVE-THIS-cybersource.com.au> writes: > It didn't take me long to get used to thinking in zero-based indexes, > but years later, I still find it hard to *talk* in zero-based indexes. > It's bad enough saying that the first element in a list in the zeroth > element, but that the second element is the first makes my head > explode... Don't say those things, then. In addition to making your head explode, they're not true. There is no “zeroth element” in a sequence. The first element in a sequence is addressed by index 0. The second element in a sequence is addressed by index 1. The last element in a sequence is addressed by index -1. In other words, it's never true (in Python) that index N addresses the Nth element of the sequence; so that's not a useful equivalence to maintain. Hope that helps. -- \ “The trouble with eating Italian food is that five or six days | `\ later you're hungry again.” —George Miller | _o__) | Ben Finney |