Re: list (range) syntax
Ryan Ginstrom wrote: On Behalf Of Steven D'Aprano Because in common English, counting starts at 1 and ranges normally include both end points (that is, it is a closed interval). If you say I'll be away from the 4th to the 7th and then turn up on the 7th, nearly everyone will wonder why you're back a day early. Actually, I think this illustrates the point about confusion, because in the United States at least, the 4th to the 7th will not necessarily include the 7th. That's why it's common to use circumlocutions like the 4th through the 7th and the 4th to the 7th, inclusive when one wants to be sure. [slightly OT] A better example would be 10 to 12 people, which translates to 10, 11, or 12 people and hardly ever 10 or 11 people. -- http://mail.python.org/mailman/listinfo/python-list
Re: [0..9] list (range) syntax
Michal Bozon wrote: The .. syntax was not meant only as something which would include the last item, but also/rather a range list syntactic shortcut: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -- [0, 1, ... 9, 10] -- [0..10] OK, I see. But I still fail to see where this is useful. All these 3 statements create a list from 0 to 10 including. If, however, the .. operator would recognize patterns before and after itself, I could see your point (e.g. [0, 1, 2, 4, 8, .. 128, 256, 512]). Buts thats pretty academic, maybe good for a specialized computation language. And I feel that my write a function argument still holds. /W -- http://mail.python.org/mailman/listinfo/python-list
[0..9] list (range) syntax
many Python newcomers are confused why range(10), does not include 10. If there was a proposal for the new syntax for ranges, which is known e.g. from Pascal or Ruby... [0..10] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ...is there a chance to be approved ? We have had a short discussion on it at the irc, I hope that the fact that nobody agreed it is a good idea was just an accident :) -m. PS: to dream further.. (0..10) generator object at 0xb7618dac or (0..10) (0..10) or (0..10) range(0, 11) -- http://mail.python.org/mailman/listinfo/python-list
Re: [0..9] list (range) syntax
Michal Bozon wrote: many Python newcomers are confused why range(10), does not include 10. It produces a list of ten elements. Also the documentation is quite clear on the topic. And lastly: This will probably really bother you for a week, then no more. If there was a proposal for the new syntax for ranges, which is known e.g. from Pascal or Ruby... [0..10] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ...is there a chance to be approved ? Quite close to none. It is too much cosmetics and too little enhancement. What would that make possible that is impossible by now or what would that make easier that is really hard? And if you really need something like that, write a function: def fullrange(start, end): r = range(start, end) r.append(end) return r /W -- http://mail.python.org/mailman/listinfo/python-list
Re: list (range) syntax
On Oct 24, 5:44 pm, Michal Bozon [EMAIL PROTECTED] wrote: many Python newcomers are confused why range(10), does not include 10. How can they be confused? Does base 10 have a digit ten? Does base 2 have a digit two? Does base 16 have a digit sixteen? Haven't you stopped counting on your fingers when you leave grade school? If there was a proposal for the new syntax for ranges, which is known e.g. from Pascal or Ruby... [0..10] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ...is there a chance to be approved ? These go to 11. We have had a short discussion on it at the irc, I hope that the fact that nobody agreed it is a good idea was just an accident :) Wait a minute...comp.lang.python. I must have accidentally gotten into the wrong newsgroup. -m. PS: to dream further.. (0..10) generator object at 0xb7618dac or (0..10) (0..10) or (0..10) range(0, 11) -- http://mail.python.org/mailman/listinfo/python-list
Re: [0..9] list (range) syntax
On Thu, 25 Oct 2007 01:16:57 +0200, Wildemar Wildenburger wrote: Michal Bozon wrote: many Python newcomers are confused why range(10), does not include 10. It produces a list of ten elements. Also the documentation is quite clear on the topic. And lastly: This will probably really bother you for a week, then no more. If there was a proposal for the new syntax for ranges, which is known e.g. from Pascal or Ruby... [0..10] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ...is there a chance to be approved ? Quite close to none. It is too much cosmetics and too little enhancement. What would that make possible that is impossible by now or what would that make easier that is really hard? And if you really need something like that, write a function: def fullrange(start, end): r = range(start, end) r.append(end) return r /W This is something completely different. The .. syntax was not meant only as something which would include the last item, but also/rather a range list syntactic shortcut: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -- [0, 1, ... 9, 10] -- [0..10] -m. -- http://mail.python.org/mailman/listinfo/python-list
Re: list (range) syntax
On Wed, 24 Oct 2007 16:28:20 -0700, [EMAIL PROTECTED] wrote: On Oct 24, 5:44 pm, Michal Bozon [EMAIL PROTECTED] wrote: many Python newcomers are confused why range(10), does not include 10. How can they be confused? Because in common English, counting starts at 1 and ranges normally include both end points (that is, it is a closed interval). If you say I'll be away from the 4th to the 7th and then turn up on the 7th, nearly everyone will wonder why you're back a day early. Does base 10 have a digit ten? Does base 2 have a digit two? Does base 16 have a digit sixteen? Haven't you stopped counting on your fingers when you leave grade school? range(N) is not designed to return the digits used in base N strings, and any connection is weak (what base does range(3, 25, 4) correspond to?). What little correspondence there is is an accidental coincidence of how we write numbers, not a fundamental fact about half-open intervals like range(). Having said that, and regardless of common English usage, using half-open intervals almost always leads to simpler programming and fewer errors. Creating syntax support for beginners to make extra off-by-one bugs is a terrible idea, no matter how seductive it seems for newbies. I know Ruby has (to my mind confusing!) support for both closed and half-open intervals, but I wonder how useful it is in practice? Ruby expression = Python equivalent 1..5 = range(1, 6) 1...5 = range(1, 5) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
RE: list (range) syntax
On Behalf Of Steven D'Aprano Because in common English, counting starts at 1 and ranges normally include both end points (that is, it is a closed interval). If you say I'll be away from the 4th to the 7th and then turn up on the 7th, nearly everyone will wonder why you're back a day early. Actually, I think this illustrates the point about confusion, because in the United States at least, the 4th to the 7th will not necessarily include the 7th. That's why it's common to use circumlocutions like the 4th through the 7th and the 4th to the 7th, inclusive when one wants to be sure. At any rate, I also think that having range(1, 10) or a similar construct mean one to ten (inclusive g) is a bad idea. Ruby's philosophy is obviously different, which is probably fine as long as you know your tradeoffs. Regards, Ryan Ginstrom -- http://mail.python.org/mailman/listinfo/python-list
Re: list (range) syntax
On Oct 24, 6:44 pm, Michal Bozon [EMAIL PROTECTED] wrote: many Python newcomers are confused why range(10), does not include 10. If there was a proposal for the new syntax for ranges, which is known e.g. from Pascal or Ruby... [0..10] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ...is there a chance to be approved ? We have had a short discussion on it at the irc, I hope that the fact that nobody agreed it is a good idea was just an accident :) No, sorry, it's just not going to happen. In fact, the opposite is happening. Python is removing the few cases that use a closed interval. For example, random.randint(a,b), which returned a random integer in range a to b inclusive, was deprecated in favor of random.randrange(a,b), which generates a random integer in range a to b, not inclusive. The advantages of open ranges are especially apparent to someone like me, who uses Python at home, then has to go to work and Matlab. It's not that I accidentally use open intervals a lot (I've gotten into the habit of making sure I am using closed intervals whenever my tension level is high :), but all the extra +1s and -1s that I need when splicing arrays gets pretty old. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list