Re: Python while loop

2016-11-30 Thread John Gordon
In <0c642381-4dd2-48c5-bb22-b38f2d5b2...@googlegroups.com> paul.garcia2...@gmail.com writes: > Write a program which prints the sum of numbers from 1 to 101 > (1 and 101 are included) that are divisible by 5 (Use while loop) > x=0 > count=0 > while x<=100: > if x%5==0: >

Re: Python while loop

2016-11-29 Thread BartC
On 29/11/2016 23:58, paul.garcia2...@gmail.com wrote: Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop) This is the code: x=0 count=0 while x<=100: if x%5==0: count=count+x x=x+1 print(count) This

Re: Python while loop

2016-11-29 Thread MRAB
On 2016-11-29 23:58, paul.garcia2...@gmail.com wrote: Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop) This is the code: x=0 count=0 while x<=100: if x%5==0: count=count+x x=x+1 print(count)

Python while loop

2016-11-29 Thread paul . garcia2345
Write a program which prints the sum of numbers from 1 to 101 ( 1 and 101 are included) that are divisible by 5 (Use while loop) This is the code: x=0 count=0 while x<=100: if x%5==0: count=count+x x=x+1 print(count) Question: How does python know what count means ? I

Re: Python While loop Takes too much time.

2014-07-01 Thread Jaydeep Patil
On Monday, 30 June 2014 18:16:21 UTC+5:30, Peter Otten wrote: Jaydeep Patil wrote: I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below

Re: Python While loop Takes too much time.

2014-07-01 Thread Peter Otten
Jaydeep Patil wrote: Dear Peter, I have tested code written by you. But still it is taking same time. Too bad ;( If you run the equivalent loop written in Basic from within Excel -- is that faster? If you run the loop in Python with some made-up data instead of that fetched from Excel

Re: Python While loop Takes too much time.

2014-07-01 Thread Denis McMahon
On Tue, 01 Jul 2014 14:40:18 +0200, Peter Otten wrote: What I'm trying to tell you: you need to put in some work to identify the culprit... His next question was how do I read a range from excel, please give me an example I gave him an example of using google to search for solutions to his

Python While loop Takes too much time.

2014-06-30 Thread Jaydeep Patil
I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below function. Why it is taking too much time? Code: def transientTestDict(self,ws,startrow,startcol):

Re: Python While loop Takes too much time.

2014-06-30 Thread Peter Otten
Jaydeep Patil wrote: I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below function. Why it is taking too much time? Code: def

Re: Python While loop Takes too much time.

2014-06-30 Thread marco . nawijn
On Monday, June 30, 2014 1:32:23 PM UTC+2, Jaydeep Patil wrote: I have did excel automation using python. In my code I am creating python dictionaries for different three columns data at a time.There are are many rows above 4000. Lets have look in below function. Why it is taking too much

Re: Python While loop Takes too much time.

2014-06-30 Thread Gregory Ewing
marco.naw...@colosso.nl wrote: In the past I even dumped an EXCEL sheet as a CSV file That's probably the only way you'll speed things up significantly. In my experience, accessing Excel via COM is abysmally slow no matter how you go about it. -- Greg --

Re: python for loop

2013-07-10 Thread Chris Nash
The first item in a sequence is at index zero because it is that far away from the beginning. The second item is one away from the beginning. That is the reason for zero-based indexing. -- http://mail.python.org/mailman/listinfo/python-list

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-04 Thread Ulrich Eckhardt
Am 01.03.2013 17:28, schrieb Isaac Won: What I really want to get from this code is m1 as I told. For this purpose, for instance, values of fpsd upto second loop and that from third loop should be same, but they are not. Actually it is my main question. You are not helping yourself... In

Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
try to make my triple nested loop working. My code would be: c = 4 y1 = [] m1 = [] std1 = [] while c 24: c = c + 1 a = [] f.seek(0,0) for columns in ( raw.strip().split() for raw in f ): a.append(columns[c])

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Ulrich Eckhardt
Am 01.03.2013 09:59, schrieb Isaac Won: try to make my triple nested loop working. My code would be: c = 4 [...] while c 24: c = c + 1 This is bad style and you shouldn't do that in python. The question that comes up for me is whether something else is modifying c in that loop,

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Joel Goldstick
On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt ulrich.eckha...@dominolaser.com wrote: Am 01.03.2013 09:59, schrieb Isaac Won: try to make my triple nested loop working. My code would be: c = 4 [...] while c 24: c = c + 1 This is bad style and you shouldn't do that in

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Chris Angelico
On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won winef...@gmail.com wrote: while c 24: for columns in ( raw.strip().split() for raw in f ): while d 335: Note your indentation levels: the code does not agree with your subject line. The third loop is not actually inside your second.

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
Thank you, Chris. I just want to acculate value from y repeatedly. If y = 1,2,3...10, just have a [1,2,3...10] at onece. On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won winef...@gmail.com wrote: while c 24: for columns in

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
On Friday, March 1, 2013 7:41:05 AM UTC-6, Chris Angelico wrote: On Fri, Mar 1, 2013 at 7:59 PM, Isaac Won winef...@gmail.com wrote: while c 24: for columns in ( raw.strip().split() for raw in f ): while d 335: Note your indentation levels: the code does not

Re: Triple nested loop python (While loop insde of for loop inside of while loop)

2013-03-01 Thread Isaac Won
Thank you Ulich for reply, What I really want to get from this code is m1 as I told. For this purpose, for instance, values of fpsd upto second loop and that from third loop should be same, but they are not. Actually it is my main question. Thank you, Isaac On Friday, March 1, 2013 6:00:42 AM

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi Roy, On Feb 11, 2013, at 10:24 AM, Roy Smith r...@panix.com wrote: Is this server that you're talking to something that you have control over, i.e. are you stuck with this protocol? Given a choice, I'd go with something like JSON, for which pre-existing libraries for every language

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi Dave, On Feb 11, 2013, at 9:22 AM, Dave Angel da...@davea.name wrote: Exactly how are you sending hexadecimal ? If that 0xad (which is only one byte, what about the other 3 ?) is intended to be a C description, then it's certainly not hex, it's binary. And probably little-endian, to

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
Hi MRAB, My code now works thanks to your advice. {msgver: 1.0, msgid: 200, subcode: 100, appver: 1.0, appid: 1.0, data: {1: igb0, 2: igb1, ifcnt: 2}} connected to misty:8080 sending data 138 bytes sent: 0x86{msgver: 1.0, msgid: 200, subcode: 100, appver: 1.0, appid: 1.0, data: {1: igb0, 2:

Re: Python recv loop

2013-02-11 Thread MRAB
On 2013-02-11 14:56, Ihsan Junaidi Ibrahim wrote: Hi Roy, On Feb 11, 2013, at 10:24 AM, Roy Smith r...@panix.com wrote: Is this server that you're talking to something that you have control over, i.e. are you stuck with this protocol? Given a choice, I'd go with something like JSON, for

Re: Python recv loop

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote: I probably wouldn't make it fixed length. I'd have the length in decimal followed by, say, \n. Or even followed by any non-digit. Chances are your JSON data begins with a non-digit, so you'd just have to insert a space in

Re: Python recv loop

2013-02-11 Thread Dave Angel
On 02/11/2013 10:02 AM, Ihsan Junaidi Ibrahim wrote: snip print 'message length is {0}'.format(nbuf) while True: buf = sock.recv(nbuf) if not buf: break This loop doesn't terminate till buf is zero length, which it will be eventually. At that

Re: Python recv loop

2013-02-11 Thread Ihsan Junaidi Ibrahim
On Feb 11, 2013, at 11:24 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote: I probably wouldn't make it fixed length. I'd have the length in decimal followed by, say, \n. Or even followed by any non-digit. Chances are your

Re: Python recv loop

2013-02-11 Thread Chris Angelico
On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim ih...@grep.my wrote: On Feb 11, 2013, at 11:24 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote: I probably wouldn't make it fixed length. I'd have the length in decimal

Re: Python recv loop

2013-02-11 Thread Roy Smith
In article mailman.1655.1360594595.2939.python-l...@python.org, Ihsan Junaidi Ibrahim ih...@grep.my wrote: I'm running JSON for my application messaging protocol but with JSON and python default unordered dict, there's no guarantee if I put in the length key in the JSON message, it will be

Re: Python recv loop

2013-02-11 Thread MRAB
On 2013-02-12 02:20, Chris Angelico wrote: On Tue, Feb 12, 2013 at 12:41 PM, Ihsan Junaidi Ibrahim ih...@grep.my wrote: On Feb 11, 2013, at 11:24 PM, Chris Angelico ros...@gmail.com wrote: On Tue, Feb 12, 2013 at 2:11 AM, MRAB pyt...@mrabarnett.plus.com wrote: I probably wouldn't make it

Python recv loop

2013-02-10 Thread Ihsan Junaidi Ibrahim
Hi, I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server. I have coded the first 4 bytes (in hexadecimal) of message coming in from the server to specify the length

Re: Python recv loop

2013-02-10 Thread Dave Angel
On 02/10/2013 07:48 PM, Ihsan Junaidi Ibrahim wrote: Hi, I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server. I have coded the first 4 bytes (in hexadecimal) of

Re: Python recv loop

2013-02-10 Thread MRAB
On 2013-02-11 00:48, Ihsan Junaidi Ibrahim wrote: Hi, I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server. I have coded the first 4 bytes (in hexadecimal) of

Re: Python recv loop

2013-02-10 Thread Roy Smith
In article mailman.1612.1360544258.2939.python-l...@python.org, Ihsan Junaidi Ibrahim ih...@grep.my wrote: I'm implementing a python client connecting to a C-backend server and am currently stuck to as to how to proceed with receiving variable-length byte stream coming in from the server.

Question of Python second loop break and indexes

2012-05-09 Thread lilin Yi
//final_1 is a list of Identifier which I need to find corresponding files(four lines) in x(x is the file) and write following four lines in a new file. //because the order of the identifier is the same, so after I find the same identifier in x , the next time I want to start from next index in

Re: Question of Python second loop break and indexes

2012-05-09 Thread MRAB
On 09/05/2012 09:36, lilin Yi wrote: //final_1 is a list of Identifier which I need to find corresponding files(four lines) in x(x is the file) and write following four lines in a new file. //because the order of the identifier is the same, so after I find the same identifier in x , the next

Re: Question of Python second loop break and indexes

2012-05-09 Thread Ulrich Eckhardt
Am 09.05.2012 10:36, schrieb lilin Yi: //final_1 is a list of Identifier which I need to find corresponding files(four lines) in x(x is the file) and write following four lines in a new file. //because the order of the identifier is the same, so after I find the same identifier in x , the

Re: Python 'for' loop is memory inefficient

2009-08-18 Thread exarkun
On 03:56 am, tjre...@udel.edu wrote: exar...@twistedmatrix.com wrote: There's a lot of things in Python that I don't strictly *need*. That doesn't mean that they wouldn't be welcome if I could have them. Getting rid of the range/xrange dichotomy would improve things. The developers agreed a

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun
On 02:12 am, pavlovevide...@gmail.com wrote: On Aug 16, 3:35�pm, sturlamolden sturlamol...@yahoo.no wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:         Well, the alternative would be to have two keywords for looping: one for your simple incrementing integer

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun
On 01:53 am, pavlovevide...@gmail.com wrote: On Aug 16, 6:28�pm, exar...@twistedmatrix.com wrote: On 01:23 am, benjamin.kap...@case.edu wrote: On Sun, Aug 16, 2009 at 6:35 PM, sturlamolden sturlamol...@yahoo.no wrote: A compiler could easily recognise a statement like � for i in range(n):

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun
On 01:44 am, http wrote: exar...@twistedmatrix.com writes: Although I think PyPy also recognizes this case and makes it as efficient as using xrange, and does so without breaking any rules. How can pypy possibly know that the user hasn't assigned some other value to range? It doesn't really

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread sturlamolden
On 16 Aug, 19:12, Carl Banks pavlovevide...@gmail.com wrote: If you don't care about the dynamic stuff why don't you just use Cython?  Or quit complaining and just use xrange. I think you are the only one complaining here. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread MRAB
exar...@twistedmatrix.com wrote: On 02:12 am, pavlovevide...@gmail.com wrote: On Aug 16, 3:35�pm, sturlamolden sturlamol...@yahoo.no wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: � � � � Well, the alternative would be to have two keywords for looping: one for your

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Stefan Behnel
Carl Banks wrote: On Aug 16, 3:35 pm, sturlamolden sturlamol...@yahoo.no wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Well, the alternative would be to have two keywords for looping: one for your simple incrementing integer loop, and another for a loop that

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Steven D'Aprano
On Sun, 16 Aug 2009 15:35:26 -0700, sturlamolden wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:         Well, the alternative would be to have two keywords for         looping: one for your simple incrementing integer loop, and another for a loop that operates over

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Stefan Behnel
John Machin wrote: On Aug 17, 8:35 am, sturlamolden sturlamol...@yahoo.no wrote: A compiler could easily recognise a statement like for i in range(n): as a simple integer loop. In fact, Cython is able to do this. Extremely easy, once users relinquish the right to replace built-in

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread David Robinow
On Sun, Aug 16, 2009 at 11:10 PM, Nobodynob...@nowhere.com wrote: Java also has iterators; it's more a case of people coming from C and BASIC. Although, some of those may have come *through* Java without abandoning old habits. You see the same thing with people coming from BASIC to C and

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Ethan Furman
Emmanuel Surleau wrote: Dr. Phillip M. Feldman wrote: [snip] def is_prime(n): for j in range(2,n): if (n % j) == 0: return False return True It seems as though Python is actually expanding range(2,n) into a list of numbers, even though this is incredibly wasteful of memory. There

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Carl Banks
On Aug 17, 4:40 am, exar...@twistedmatrix.com wrote: On 02:12 am, pavlovevide...@gmail.com wrote: On Aug 16, 3:35 pm, sturlamolden sturlamol...@yahoo.no wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:         Well, the alternative would be to have two keywords for

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread exarkun
On 06:32 pm, pavlovevide...@gmail.com wrote: On Aug 17, 4:40�am, exar...@twistedmatrix.com wrote: On 02:12 am, pavlovevide...@gmail.com wrote: On Aug 16, 3:35�pm, sturlamolden sturlamol...@yahoo.no wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: � � � �

Re: Python 'for' loop is memory inefficient

2009-08-17 Thread Terry Reedy
exar...@twistedmatrix.com wrote: There's a lot of things in Python that I don't strictly *need*. That doesn't mean that they wouldn't be welcome if I could have them. Getting rid of the range/xrange dichotomy would improve things. The developers agreed a couple of years ago. Starting using

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Emmanuel Surleau
Dr. Phillip M. Feldman wrote: [snip] def is_prime(n): for j in range(2,n): if (n % j) == 0: return False return True It seems as though Python is actually expanding range(2,n) into a list of numbers, even though this is incredibly wasteful of memory. There should be

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Steven D'Aprano
On Sun, 16 Aug 2009 08:30:54 +0200, Emmanuel Surleau wrote: [...] I will also observe that if you were to stop programming whatever language you are more familiar with in Python, and start programming Python in Python, you'll have an easier time of it. I don't see what's particularly

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Emmanuel Surleau
It's a particular unfair criticism because the critic (Ethan Furman) appears to have made a knee-jerk reaction. The some language in Python behaviour he's reacting to is the common idiom: for i in range(len(seq)): do_something_with(seq[i]) instead of the Python in Python idiom: for

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Benjamin Kaplan
not and, for the most part, you shouldn't code like that. Since you're using numbers, range/xrange is the appropriate idiom but you still have to remember that a for loop in python doesn't loop until a condition is met, it loops through an iterator until the interator says it's done. -- http://mail.python.org/mailman

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread bartc
Steven D'Aprano st...@remove-this-cybersource.com.au wrote in message news:02969972$0$20647$c3e8...@news.astraweb.com... On Fri, 14 Aug 2009 18:25:45 -0700, Dr. Phillip M. Feldman wrote: It seems as though Python is actually expanding range(2,n) into a list of numbers, even though this is

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread MRAB
bartc wrote: Steven D'Aprano st...@remove-this-cybersource.com.au wrote in message news:02969972$0$20647$c3e8...@news.astraweb.com... On Fri, 14 Aug 2009 18:25:45 -0700, Dr. Phillip M. Feldman wrote: It seems as though Python is actually expanding range(2,n) into a list of numbers, even

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread sturlamolden
On 16 Aug, 11:45, bartc ba...@freeuk.com wrote: A for-loop, for iterating over a simple sequence, should be one of the fastest things in the language. Anyone experienced with interpreted high-level languages knows this is not true. Not because iterating a sequence is expensive, but because the

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread sturlamolden
On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:         Well, the alternative would be to have two keywords for looping: one for your simple incrementing integer loop, and another for a loop that operates over the elements of some collection type. A compiler could easily

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Benjamin Kaplan
On Sun, Aug 16, 2009 at 6:35 PM, sturlamolden sturlamol...@yahoo.no wrote: A compiler could easily recognise a statement like   for i in range(n): as a simple integer loop. In fact, Cython is able to do this. but special cases aren't special enough to break the rules. --

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread John Machin
On Aug 17, 8:35 am, sturlamolden sturlamol...@yahoo.no wrote: A compiler could easily recognise a statement like    for i in range(n): as a simple integer loop. In fact, Cython is able to do this. Extremely easy, once users relinquish the right to replace built-in range with their own

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread exarkun
On 01:23 am, benjamin.kap...@case.edu wrote: On Sun, Aug 16, 2009 at 6:35 PM, sturlamolden sturlamol...@yahoo.no wrote: A compiler could easily recognise a statement like � for i in range(n): as a simple integer loop. In fact, Cython is able to do this. but special cases aren't special

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Paul Rubin
exar...@twistedmatrix.com writes: Although I think PyPy also recognizes this case and makes it as efficient as using xrange, and does so without breaking any rules. How can pypy possibly know that the user hasn't assigned some other value to range? --

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Carl Banks
On Aug 16, 6:28 pm, exar...@twistedmatrix.com wrote: On 01:23 am, benjamin.kap...@case.edu wrote: On Sun, Aug 16, 2009 at 6:35 PM, sturlamolden sturlamol...@yahoo.no wrote: A compiler could easily recognise a statement like   for i in range(n): as a simple integer loop. In fact, Cython

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Carl Banks
On Aug 16, 3:35 pm, sturlamolden sturlamol...@yahoo.no wrote: On 16 Aug, 14:57, Dennis Lee Bieber wlfr...@ix.netcom.com wrote:         Well, the alternative would be to have two keywords for looping: one for your simple incrementing integer loop, and another for a loop that operates over

Re: Python 'for' loop is memory inefficient

2009-08-16 Thread Nobody
not and, for the most part, you shouldn't code like that. Since you're using numbers, range/xrange is the appropriate idiom but you still have to remember that a for loop in python doesn't loop until a condition is met, it loops through an iterator until the interator says it's done. Java also has iterators

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Rascal
look at xrange -- http://docs.python.org/library/functions.html#xrange -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Hendrik van Rooyen
On Saturday 15 August 2009 03:25:45 Dr. Phillip M. Feldman wrote: It seems as though Python is actually expanding range(2,n) into a list of numbers, even though this is incredibly wasteful of memory. There should be a looping mechanism that generates the index variable values incrementally as

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread John Machin
On Aug 15, 11:38 am, Mark Lawrence breamore...@yahoo.co.uk wrote: Dr. Phillip M. Feldman wrote: I wrote the following correct but inefficient test of primality for purposes of demonstrating that the simplest algorithm is often not the most efficient.  But, when I try to run the following

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread Steven D'Aprano
On Fri, 14 Aug 2009 18:25:45 -0700, Dr. Phillip M. Feldman wrote: It seems as though Python is actually expanding range(2,n) into a list of numbers, even though this is incredibly wasteful of memory. There should be a looping mechanism that generates the index variable values incrementally as

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread John Nagle
Hendrik van Rooyen wrote: On Saturday 15 August 2009 03:25:45 Dr. Phillip M. Feldman wrote: And while you are about it, you may as well teach them that it is much better to do a multiplication than a division. Actually, division speed hasn't been much of an issue in years. Arithmetic

Re: Python 'for' loop is memory inefficient

2009-08-15 Thread MRAB
John Nagle wrote: Hendrik van Rooyen wrote: On Saturday 15 August 2009 03:25:45 Dr. Phillip M. Feldman wrote: And while you are about it, you may as well teach them that it is much better to do a multiplication than a division. Actually, division speed hasn't been much of an issue in

Python 'for' loop is memory inefficient

2009-08-14 Thread Dr. Phillip M. Feldman
the index variable values incrementally as they are needed. -- View this message in context: http://www.nabble.com/Python-%27for%27-loop-is-memory-inefficient-tp24980842p24980842.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo

Re: Python 'for' loop is memory inefficient

2009-08-14 Thread Stephen Hansen
It seems as though Python is actually expanding range(2,n) into a list of numbers, even though this is incredibly wasteful of memory. There should be a looping mechanism that generates the index variable values incrementally as they are needed. This has nothing to do with Python's for loop

Re: Python 'for' loop is memory inefficient

2009-08-14 Thread Mark Lawrence
Dr. Phillip M. Feldman wrote: I wrote the following correct but inefficient test of primality for purposes of demonstrating that the simplest algorithm is often not the most efficient. But, when I try to run the following code with a value of n that is large enough to produce a significant

Re: Python 'for' loop is memory inefficient

2009-08-14 Thread Ethan Furman
Dr. Phillip M. Feldman wrote: I wrote the following correct but inefficient test of primality for purposes of demonstrating that the simplest algorithm is often not the most efficient. But, when I try to run the following code with a value of n that is large enough to produce a significant

Re: Python 'for' loop is memory inefficient

2009-08-14 Thread r
On Aug 14, 8:25 pm, Dr. Phillip M. Feldman pfeld...@verizon.net wrote: I wrote the following correct but inefficient test of primality for purposes of demonstrating that the simplest algorithm is often not the most efficient.  But, when I try to run the following code with a value of n that is

Re: python for loop

2009-04-07 Thread Aahz
In article pecora-d381e9.08361703042...@ra.nrl.navy.mil, Lou Pecora pec...@anvil.nrl.navy.mil wrote: In article 5c92e9bd-1fb4-4c01-a928-04d7f6733...@e21g2000yqb.googlegroups.com, Aaron Brady castiro...@gmail.com wrote: Did I tell you guys that 'natural' has 38 definitions at dictionary.com?

Re: python for loop

2009-04-03 Thread Lie
On Apr 2, 5:29 pm, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Wed, 01 Apr 2009 21:58:47 -0700, Lie wrote: On Apr 1, 7:06 pm, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: There is a major clash between the names of ordinals in human languages and

Re: python for loop

2009-04-03 Thread Lou Pecora
In article 5c92e9bd-1fb4-4c01-a928-04d7f6733...@e21g2000yqb.googlegroups.com, Aaron Brady castiro...@gmail.com wrote: On Apr 2, 6:34 pm, Tim Wintle tim.win...@teamrubber.com wrote: On Thu, 2009-04-02 at 15:16 -0700, Emile van Sebille wrote: Lou Pecora wrote: Confusion only comes when

Re: python for loop

2009-04-03 Thread MRAB
Lie wrote: [snip] Alternatively: One friend of mine half-seriously advanced the following thesis: We should count from zero. But first is, etymologically, a diminution of foremost, and (as TomStambaugh says) should mean 0th when we count from 0. And second is from the Latin secundus, meaning

Re: python for loop

2009-04-03 Thread alex23
On Apr 3, 10:36 pm, Lou Pecora pec...@anvil.nrl.navy.mil wrote:  Aaron Brady castiro...@gmail.com wrote: Did I tell you guys that 'natural' has 38 definitions at dictionary.com? Amazing.  I suggest you pick the one that fits best. You mean the one that feels most natural? --

Re: python for loop

2009-04-03 Thread Aaron Brady
On Apr 3, 10:43 am, alex23 wuwe...@gmail.com wrote: On Apr 3, 10:36 pm, Lou Pecora pec...@anvil.nrl.navy.mil wrote:  Aaron Brady castiro...@gmail.com wrote: Did I tell you guys that 'natural' has 38 definitions at dictionary.com? Amazing.  I suggest you pick the one that fits best.

Re: python for loop

2009-04-02 Thread Lie
On Apr 2, 4:05 pm, Aaron Brady castiro...@gmail.com wrote: On Apr 1, 11:58 pm, Lie lie.1...@gmail.com wrote: On Apr 1, 7:06 pm, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: There is a major clash between the names of ordinals in human languages and zero-based counting.

Re: python for loop

2009-04-02 Thread Steven D'Aprano
On Thu, 02 Apr 2009 04:23:32 +, John O'Hagan wrote: Beyond being part of a conventionally-ordered set of keys, what can an ordinality of zero actually mean? (That's a sincere question.) In set theory, you start by defining the integers like this: 0 is the cardinality (size) of the empty

Re: python for loop

2009-04-02 Thread Steven D'Aprano
On Wed, 01 Apr 2009 21:58:47 -0700, Lie wrote: On Apr 1, 7:06 pm, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: There is a major clash between the names of ordinals in human languages and zero-based counting. In human languages, the Nth-ordinal item comes in position N. You

Re: python for loop

2009-04-02 Thread Carl Banks
On Apr 1, 9:23 pm, John O'Hagan resea...@johnohagan.com wrote: Despite being thoroughly acclimatised to zero-based indexing and having no wish to change it, I'm starting to see the OP's point. Many of the arguments presented in this thread in favour of zero-based indexing have rather been

Re: python for loop

2009-04-02 Thread Aaron Brady
On Apr 2, 1:29 am, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Wed, 01 Apr 2009 21:58:47 -0700, Lie wrote: On Apr 1, 7:06 pm, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: There is a major clash between the names of ordinals in human languages and

Re: python for loop

2009-04-02 Thread Hrvoje Niksic
Carl Banks pavlovevide...@gmail.com writes: This is unforgiveable, not only changing the indexing semantics of Python (because a user would have NO CLUE that something underlying has been changed, and thus it should never be done), but also for the needless abuse of exec. Then I guess you'd

Re: python for loop

2009-04-02 Thread Arnaud Delobelle
Carl Banks wrote: On Apr 1, 2:32 pm, Arnaud Delobelle arno...@googlemail.com wrote: Check the date on the line above (and the PS in that post). If I were your boss and you ever pulled something like this, your ass would be so fired. This is unforgiveable, not only changing the indexing

Re: python for loop

2009-04-02 Thread Carl Banks
On Apr 1, 11:28 pm, Hrvoje Niksic hnik...@xemacs.org wrote: Carl Banks pavlovevide...@gmail.com writes: This is unforgiveable, not only changing the indexing semantics of Python (because a user would have NO CLUE that something underlying has been changed, and thus it should never be done),

Re: python for loop

2009-04-02 Thread John O'Hagan
On Thu, 2 Apr 2009, Steven D'Aprano wrote: On Thu, 02 Apr 2009 04:23:32 +, John O'Hagan wrote: Beyond being part of a conventionally-ordered set of keys, what can an ordinality of zero actually mean? (That's a sincere question.) [snip erudite definition of cardinality] For

Re: python for loop

2009-04-02 Thread Arnaud Delobelle
Steven D'Aprano wrote: In set theory, you start by defining the integers like this: 0 is the cardinality (size) of the empty set, the set with nothing in it. 1 is the cardinality of the set of empty sets, that is, the set containing nothing but the empty set. 2 is the cardinality of the

Re: python for loop

2009-04-02 Thread Gabriel Genellina
En Wed, 01 Apr 2009 08:04:12 -0300, andrew cooke and...@acooke.org escribió: something i don't think has been mentioned much - if you're using range() in your python code then you're almost always doing it wrong. i just grepped lepl and i use range 20 times in 9600 lines of code. out of

Re: python for loop

2009-04-02 Thread Lou Pecora
In article pan.2009.04.02.06.28...@remove.this.cybersource.com.au, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: So an ordinality of zero just means the number of elements of something that doesn't exist. You do realize that will give most people headaches. :-) -- -- Lou

Re: python for loop

2009-04-02 Thread Tim Wintle
On Thu, 2009-04-02 at 06:28 +, Steven D'Aprano wrote: In set theory, you start by defining the integers like this: snip 0 = len( {} ) 1 = len( {{}} ) 2 = len( {{}, {{}}} ) 3 = len( {{}, {{}}, {{}, {{}}} ) etc. not quite len() - surely you mean something like any object along with an

Re: python for loop

2009-04-02 Thread Lou Pecora
In article bd70785c-1e86-4437-a14e-d84028f57...@k19g2000prh.googlegroups.com, Carl Banks pavlovevide...@gmail.com wrote: I think people were being facetious. To me the first item in the list is x[0]--ordinal does not match cardinal. However, I don't use ordinals much when talking about

Re: python for loop

2009-04-02 Thread Emile van Sebille
Lou Pecora wrote: Confusion only comes when you try to force the defintion of one of them on the other and then say it's illogical or not natural. Both are natural. Consider the French 'Premiere etage' vs the American 'First Floor' Emile --

Re: python for loop

2009-04-02 Thread Tim Wintle
On Thu, 2009-04-02 at 15:16 -0700, Emile van Sebille wrote: Lou Pecora wrote: Confusion only comes when you try to force the defintion of one of them on the other and then say it's illogical or not natural. Both are natural. Consider the French 'Premiere etage' vs the American 'First

Re: python for loop

2009-04-02 Thread Aaron Brady
On Apr 2, 6:34 pm, Tim Wintle tim.win...@teamrubber.com wrote: On Thu, 2009-04-02 at 15:16 -0700, Emile van Sebille wrote: Lou Pecora wrote: Confusion only comes when you try to force the defintion of one of them on the other and then say it's illogical or not natural.  Both are

  1   2   >