Re: Python 2.7 range Function provokes a Memory Error

2023-03-06 Thread Chris Angelico
On Tue, 7 Mar 2023 at 16:53, Stephen Tucker wrote: > > Hi again, > > I tried xrange, but I got an error telling me that my integer was too big > for a C long. > > Clearly, xrange in Py2 is not capable of dealing with Python (that is, > possibly very long) integers. That's because Py2 has two diff

Re: Python 2.7 range Function provokes a Memory Error

2023-03-06 Thread Stephen Tucker
Jon Ribbens via Python-list < python-list@python.org> wrote: > On 2023-03-02, Stephen Tucker wrote: > > The range function in Python 2.7 (and yes, I know that it is now > > superseded), provokes a Memory Error when asked to deiliver a very long > > list of values. > >

Re: Python 2.7 range Function provokes a Memory Error

2023-03-02 Thread Jon Ribbens via Python-list
On 2023-03-02, Stephen Tucker wrote: > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produces a list which it then >

Re: Python 2.7 range Function provokes a Memory Error

2023-03-02 Thread Chris Angelico
On Thu, 2 Mar 2023 at 22:27, Stephen Tucker wrote: > > Hi, > > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produ

Re: Python 2.7 range Function provokes a Memory Error

2023-03-02 Thread 2QdxY4RzWzUUiLuE
On 2023-03-02 at 11:25:49 +, Stephen Tucker wrote: > The range function in Python 2.7 (and yes, I know that it is now > superseded), provokes a Memory Error when asked to deiliver a very long > list of values. > > I assume that this is because the function produces a lis

Python 2.7 range Function provokes a Memory Error

2023-03-02 Thread Stephen Tucker
Hi, The range function in Python 2.7 (and yes, I know that it is now superseded), provokes a Memory Error when asked to deiliver a very long list of values. I assume that this is because the function produces a list which it then iterates through. 1. Does the range function in Python 3.x

Re: Teaching the "range" function in Python 3

2017-07-02 Thread Rick Johnson
On Saturday, July 1, 2017 at 12:48:39 AM UTC-5, Christian Gollwitzer wrote: > Am 30.06.17 um 04:33 schrieb Rick Johnson: > > And to further drive home the point, you can manually > > insert a list literal to prove this: > > > > >>> range(10) > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > >>

Re: Teaching the "range" function in Python 3

2017-07-02 Thread Rick Johnson
On Thursday, June 29, 2017 at 9:58:23 PM UTC-5, Chris Angelico wrote: > On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson > > A better *FIRST* example would be something like this: > > > > def add(x, y): > > return x + y > > > > When teaching a student about functions, the first step is >

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Christian Gollwitzer
Am 30.06.17 um 04:33 schrieb Rick Johnson: And to further drive home the point, you can manually insert a list literal to prove this: >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> for value in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]: ... print(value) ... 0 1 No

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Chris Angelico
On Sat, Jul 1, 2017 at 1:25 PM, MRAB wrote: > On 2017-07-01 03:12, Stefan Ram wrote: >> >> Terry Reedy writes: >>> >>> range is a class, not a function in the strict sense. >> >> >>»the built-in function range() returns an iterator of integers« >> >> The Python Language Reference, Re

Re: Teaching the "range" function in Python 3

2017-06-30 Thread MRAB
On 2017-07-01 03:12, Stefan Ram wrote: Terry Reedy writes: range is a class, not a function in the strict sense. »the built-in function range() returns an iterator of integers« The Python Language Reference, Release 3.6.0, 8.3 The for statement Python 3.6.1 (v3.6.1:69c0db5, Mar

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Terry Reedy
On 6/30/2017 1:07 PM, Irv Kalb wrote: Thanks to everyone who responded to my question about teaching the range function. range is a class, not a function in the strict sense. Classes represent concepts. Instances of classes represent instances of the concept. Range represent the concept

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Irv Kalb
word "collection" for things you iterate > over (rather than the concrete term "list"). So you can loop through > (or iterate over) a collection of explicitly given numbers: > Thanks to everyone who responded to my question about teaching the range function. I par

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Chris Angelico
On Sat, Jul 1, 2017 at 2:17 AM, Stefan Ram wrote: > However, to my defense, I must say that in this post my intend > was to demonstrate what is happening /behind the curtains/ when > the »for« loop is running, so in this special case, it might be > appropriate to use a function that otherw

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Steve D'Aprano
On Fri, 30 Jun 2017 09:17 am, Stefan Ram wrote: b = a.__iter__() Don't do that. Dunder ("Double UNDERscore") methods like __iter__ should only be called by the Python interpreter, not by the programmer. The right way to create an iterator is to call the built-in function iter: b = iter(a)

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Steve D'Aprano
Hello Irv, and welcome! Good to have a teacher of Python here! On Fri, 30 Jun 2017 06:57 am, Irv Kalb wrote: [...] > Now I am looking at the change in the range function. I completely understand > the differences between, and the reasons for, how range works differently in > Python 2

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Peter Otten
Gregory Ewing wrote: > Don't start with range(). Start with lists, and introduce the for > loop as a way to iterate over lists. Leave range() until much later. > You should be able to go a *long* way without it -- it's quite > rare to need to iterate over a range of ints in idiomatic Python > code

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Rustom Mody
On Friday, June 30, 2017 at 8:28:23 AM UTC+5:30, Chris Angelico wrote: > On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson wrote: > > A better *FIRST* example would be > > something like this: > > > > def add(x, y): > > return x + y > > > > When teaching a student about functions, the firs

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Chris Angelico
On Fri, Jun 30, 2017 at 12:33 PM, Rick Johnson wrote: > A better *FIRST* example would be > something like this: > > def add(x, y): > return x + y > > When teaching a student about functions, the first step is > to help them understand *WHY* they need to use functions, > and the second

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Rick Johnson
On Thursday, June 29, 2017 at 4:01:07 PM UTC-5, Irv Kalb wrote: > > [...] > > But Python 3's version of the range function has been > turned into a generator. Again, I understand why this > happened, and I agree that this is a good change. The > problem is, how can

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Gregory Ewing
Irv Kalb wrote: In Python 2, I easily demonstrated the range function using a simple print statement: print range(0, 10) I discussed how range returns a list. I gave many examples of different values being passed into range, and printing the resulting lists. Next, I introduced the concept of

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Cameron Simpson
On 29Jun2017 13:57, Irv Kalb wrote: Now I am looking at the change in the range function. I completely understand the differences between, and the reasons for, how range works differently in Python 2 vs Python 3. The problem that I've run into has to do with how to explain what range

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Ian Kelly
On Thu, Jun 29, 2017 at 2:57 PM, Irv Kalb wrote: > Now I am looking at the change in the range function. I completely > understand the differences between, and the reasons for, how range works > differently in Python 2 vs Python 3. The problem that I've run into has to &g

Re: Teaching the "range" function in Python 3

2017-06-29 Thread Chris Angelico
On Fri, Jun 30, 2017 at 6:57 AM, Irv Kalb wrote: > I am wondering if other teachers have run into this. Is this a real problem? > If so, is there any other way of explaining the concept without getting into > the underlying details of how a generator works? Do you think it would be > helpful

Teaching the "range" function in Python 3

2017-06-29 Thread Irv Kalb
updating my curriculum to Python 3's syntax and concepts. In general, it's all going fine, the changes from raw_input to input, and print from a keyword/statement to the print function have been very straight-forward. But ... Now I am looking at the change in the range function. I

Re: inside-out range function

2009-04-28 Thread William Clifford
On Apr 27, 10:50 pm, Paul Rubin wrote: > William Clifford writes: > > def enrag(start, stop=None, step=1): > >     '''Yield a range of numbers from inside-out, evens on left.''' > >     >>> list(enrag(10)) >     [8, 6, 4, 2, 0, 1, 3, 5, 7, 9]     > > ok, but: > >    

Re: inside-out range function

2009-04-28 Thread Scott David Daniels
Steven D'Aprano wrote: ... I wrote a similar function to do this: def monge_shuffle(deck): if len(deck) % 2: # Odd number of items. deck[:] = deck[0::2] + deck[1::2][::-1] else: # Even number of items. deck[:] = deck[1::2] + deck[0::2][::-1] return deck Oooh, shiny

Re: inside-out range function

2009-04-27 Thread Paul Rubin
William Clifford writes: > def enrag(start, stop=None, step=1): > '''Yield a range of numbers from inside-out, evens on left.''' >>> list(enrag(10)) [8, 6, 4, 2, 0, 1, 3, 5, 7, 9] ok, but: >>> list(enrag(10,20)) [18, 16, 14, 12, 10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19] is

Re: inside-out range function

2009-04-27 Thread Mensanator
On Apr 28, 12:19�am, William Clifford wrote: > On Apr 27, 9:22�pm, Steven D'Aprano > > > > > > wrote: > > On Mon, 27 Apr 2009 20:27:07 -0700, William Clifford wrote: > > > For some reason I thought I needed this code, but it turns out I don't, > > > really. > > > I need something weirder. Anyway,

Re: inside-out range function

2009-04-27 Thread William Clifford
On Apr 27, 9:22 pm, Steven D'Aprano wrote: > On Mon, 27 Apr 2009 20:27:07 -0700, William Clifford wrote: > > For some reason I thought I needed this code, but it turns out I don't, > > really. > > I need something weirder. Anyway, maybe someone else could use this. > > > def enrag(start, stop=None

Re: inside-out range function

2009-04-27 Thread Steven D'Aprano
On Mon, 27 Apr 2009 20:27:07 -0700, William Clifford wrote: > For some reason I thought I needed this code, but it turns out I don't, > really. > I need something weirder. Anyway, maybe someone else could use this. > > def enrag(start, stop=None, step=1): > '''Yield a range of numbers from in

inside-out range function

2009-04-27 Thread William Clifford
For some reason I thought I needed this code, but it turns out I don't, really. I need something weirder. Anyway, maybe someone else could use this. def enrag(start, stop=None, step=1): '''Yield a range of numbers from inside-out, evens on left.''' if stop is None: stop, start = s

Re: Range function

2005-05-15 Thread David Formosa (aka ? the Platypus)
On 15 May 2005 02:50:38 -0700, Xah Lee <[EMAIL PROTECTED]> wrote: > Here's the Perl code. Where did you learn to program? Its highly unlikely that a Perl programer would ever write a range function as there is a built in Perl function that does the same thing. If your intent is pu

Re: Range function

2005-05-15 Thread Peter Hansen
Xah Lee wrote: > the previous posted solutions are badly botched. > def Range(iMin, iMax=None, iStep=None): [snip hideous code] > # Thanks to Peter Hansen for a correction. Ohmigod, he's only made it worse and he's blaming me for it. Shows what I get for replying to a cross-posted troll messag

Re: Range function

2005-05-15 Thread Xah Lee
the previous posted solutions are badly botched. Here's a better solution. Any further correction will appear on the website instead. (http://xahlee.org/tree/tree.html) Similar change needs to be made for the Perl code... Java code will come tomorror. By the way, the code from me are not expecte

Re: Range function

2005-05-15 Thread Peter Hansen
Xah Lee wrote: > Here's the Python solution. > # implementation note: When iStep is a decimal, rounding error > # accumulates. For example, the last item returned from > # Range(0,18,0.3) is 17.7 not 18. A remedy is to turn iStep into a > # fraction and do exact arithmetics, and possibly convert th

Re: Range function

2005-05-15 Thread Xah Lee
Here's the Python solution. -- # -*- coding: utf-8 -*- # Python # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 # implementation note: When iStep is a decimal, rounding error # accumulates. For example, the last item returned from # Range(0,18,0.3) is 17.7 not 18. A remedy is to tu

Re: Range function

2005-05-15 Thread Xah Lee
Here's the Perl code. -- #! perl # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 #_ Range _ _ _ _ =pod B Range($iMax) generates the list [1, 2, ... , $iMax]. Range($iMin, $iMax) generates the list [$iMin, ... , $iMax]. Range($iMin, $iMax, $iStep) uses incr

Re: [perl-python] Range function

2005-05-12 Thread Jürgen Exner
Xah Lee wrote: > Today we'll be writing a function called Range. I don't think so. Unless you meant to write "Today WE'll be writing " > The Perl documentation is as follows. Bullshit. The Perl documentation is part of any Perl installation but you didn't link to it anywhere left alone quot

[perl-python] Range function

2005-05-12 Thread Xah Lee
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah [EMAIL PROTECTED] â http://xahlee.org/ --

[perl-python] Range function

2005-05-12 Thread Xah Lee
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. This is Perl-Python a-day. See http://xahlee.org/web/perl-python/python.html Xah [EMAIL PROTECTED] â http://xahlee.org/ --