Re: Trying to understand nested loops

2022-08-08 Thread GB
On 08/08/2022 12:59, Dan Purgert wrote: dn wrote: On 06/08/2022 11.41, avi.e.gr...@gmail.com wrote: I wonder if someone is pulling our leg as they are sending from an invalid email address of "GB " which is a bit sick. There are a number of folk who use evidently false email addresses - the

Re: Trying to understand nested loops

2022-08-08 Thread Dan Purgert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 dn wrote: > On 06/08/2022 11.41, avi.e.gr...@gmail.com wrote: >> I wonder if someone is pulling our leg as they are sending from an >> invalid email address of "GB " which is >> a bit sick. > > There are a number of folk who use evidently false email

RE: Trying to understand nested loops

2022-08-06 Thread avi.e.gross
Behalf Of Chris Angelico Sent: Saturday, August 6, 2022 8:12 AM To: python-list@python.org Subject: Re: Trying to understand nested loops On Sat, 6 Aug 2022 at 22:08, Richard Damon wrote: > > On 8/6/22 12:01 AM, Chris Angelico wrote: > > On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote:

Re: Trying to understand nested loops

2022-08-06 Thread Chris Angelico
On Sat, 6 Aug 2022 at 22:39, Richard Damon wrote: > > On 8/6/22 8:12 AM, Chris Angelico wrote: > > On Sat, 6 Aug 2022 at 22:08, Richard Damon wrote: > >> On 8/6/22 12:01 AM, Chris Angelico wrote: > >>> On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: > On Fri, Aug 5, 2022 at 12:54 PM Grant

Re: Trying to understand nested loops

2022-08-06 Thread Richard Damon
On 8/6/22 8:12 AM, Chris Angelico wrote: On Sat, 6 Aug 2022 at 22:08, Richard Damon wrote: On 8/6/22 12:01 AM, Chris Angelico wrote: On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards wrote: In C, this doesn't do what it looks like it's suppose

Re: Trying to understand nested loops

2022-08-06 Thread Chris Angelico
On Sat, 6 Aug 2022 at 22:08, Richard Damon wrote: > > On 8/6/22 12:01 AM, Chris Angelico wrote: > > On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: > >> On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards > >> wrote: > >> > >>> In C, this doesn't do what it looks like it's supposed to do. > >>> > >>

Re: Trying to understand nested loops

2022-08-06 Thread Richard Damon
On 8/6/22 12:01 AM, Chris Angelico wrote: On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards wrote: In C, this doesn't do what it looks like it's supposed to do. if (foo) do_this(); and_this(); then_do_this(); It's been quit

Re: Trying to understand nested loops

2022-08-05 Thread Chris Angelico
On Sat, 6 Aug 2022 at 13:54, Dan Stromberg wrote: > > On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards > wrote: > > > In C, this doesn't do what it looks like it's supposed to do. > > > >if (foo) > > do_this(); > > and_this(); > >then_do_this(); > > > It's been quite a while since

Re: Trying to understand nested loops

2022-08-05 Thread Dan Stromberg
On Fri, Aug 5, 2022 at 12:54 PM Grant Edwards wrote: > In C, this doesn't do what it looks like it's supposed to do. > >if (foo) > do_this(); > and_this(); >then_do_this(); > It's been quite a while since I used C, but with the right compiler flag(s), I think this may be a thing

Re: Trying to understand nested loops

2022-08-05 Thread Mladen Gogala via Python-list
On Fri, 5 Aug 2022 08:34:45 +0100, ojomooluwatolami675 wrote: > Hello, I’m new to learning python and I stumbled upon a question nested > loops. This is the question below. Can you please how they arrived at 9 > as the answer. Thanks > > var = 0 for i in range(3): > for j

RE: Trying to understand nested loops

2022-08-05 Thread avi.e.gross
write articles or books and wants to see what people think but then does not participate or tell us that is what they wanted. My point was not to tell anyone else here what to do, simply that I will be cautious with such posters as I have way better things to do! Nested loops are indeed a hard

Re: Trying to understand nested loops

2022-08-05 Thread dn
On 06/08/2022 11.41, avi.e.gr...@gmail.com wrote: > I wonder if someone is pulling our leg as they are sending from an invalid > email address of "GB " which is a bit sick. There are a number of folk who use evidently false email addresses - the OP's had me amused. Such 'hiding' is a matter for t

Re: Trying to understand nested loops

2022-08-05 Thread Dan Stromberg
On Fri, Aug 5, 2022 at 12:30 PM GB wrote: > On 05/08/2022 08:56, Frank Millman wrote: > > > BTW, there is an indentation error in your original post - line 5 should > > line up with line 4. > > As a Python beginner, I find that Python is annoyingly picky about > indents. And, the significance of

RE: Trying to understand nested loops

2022-08-05 Thread avi.e.gross
r at least that they have spent any serious time learning. -Original Message- From: Python-list On Behalf Of GB Sent: Friday, August 5, 2022 5:57 AM To: python-list@python.org Subject: Re: Trying to understand nested loops On 05/08/2022 08:56, Frank Millman wrote: > BTW, there is an inde

Re: Trying to understand nested loops

2022-08-05 Thread dn
On 06/08/2022 10.50, Dan Stromberg wrote: > On Fri, Aug 5, 2022 at 12:35 AM wrote: ... > Of if you don't have (or want) a debugger, you could change it to: > > var = 0 > for i in range(3): > print('i is', i) > for j in range(-2,-7,-2): > print('j is', j) > var += 1 > print(var) >

Re: Trying to understand nested loops

2022-08-05 Thread Dan Stromberg
On Fri, Aug 5, 2022 at 12:35 AM wrote: > Hello, I’m new to learning python and I stumbled upon a question nested > loops. This is the question below. Can you please how they arrived at 9 as > the answer. Thanks > > var = 0 > for i in range(3): > for j in range(-2,-

Re: Trying to understand nested loops

2022-08-05 Thread Mats Wichmann
On 8/5/22 03:56, GB wrote: > On 05/08/2022 08:56, Frank Millman wrote: > >> BTW, there is an indentation error in your original post - line 5 >> should line up with line 4. > > As a Python beginner, I find that Python is annoyingly picky about > indents.  And, the significance of indents is a bi

Re: Trying to understand nested loops

2022-08-05 Thread Grant Edwards
On 2022-08-05, GB wrote: >> BTW, there is an indentation error in your original post - line 5 >> should line up with line 4. > > As a Python beginner, I find that Python is annoyingly picky about > indents. And, the significance of indents is a bit of a minefield for > beginners. As a C begin

Re: Trying to understand nested loops

2022-08-05 Thread GB
On 05/08/2022 08:56, Frank Millman wrote: BTW, there is an indentation error in your original post - line 5 should line up with line 4. As a Python beginner, I find that Python is annoyingly picky about indents. And, the significance of indents is a bit of a minefield for beginners. For

Re: Trying to understand nested loops

2022-08-05 Thread Dieter Maurer
ojomooluwatolami...@gmail.com wrote at 2022-8-5 08:34 +0100: >Hello, I’m new to learning python and I stumbled upon a question nested loops. For future, more complex, questions of this kind, you might have a look at the module `pdb` in Python's runtime library. It implements a debugg

Re: Trying to understand nested loops

2022-08-05 Thread Weatherby,Gerard
It’s also a poor code example. Doing a pointless double loop is not good instructional practice, especially when simpler alternatives exist. e.g. for i in range(3): for j in range(-2.-7,-2): print(i +j ) — Gerard Weatherby | Application Architect NMRbox | NAN | Department of Molecular Biol

Re: Trying to understand nested loops

2022-08-05 Thread Cameron Simpson
On 05Aug2022 09:47, Lars Liedtke wrote: >this looks to me like it might be a piece of homework, as it would be >given by teachers or professors. > >This list has got the rule, that members do not solve other's >homework. Because very often homework is meant to sit down and think >about it. Ver

Re: Trying to understand nested loops

2022-08-05 Thread Frank Millman
On 2022-08-05 9:34 AM, ojomooluwatolami...@gmail.com wrote: Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks var = 0 for i in range(3): for j in range(-2,-7,-2): var

Re: Trying to understand nested loops

2022-08-05 Thread Lars Liedtke
um 09:34 schrieb ojomooluwatolami...@gmail.com: Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks var = 0 for i in range(3): for j in range(-2,-7,-2): var += 1 prin

Trying to understand nested loops

2022-08-05 Thread ojomooluwatolami675
Hello, I’m new to learning python and I stumbled upon a question nested loops. This is the question below. Can you please how they arrived at 9 as the answer. Thanks var = 0 for i in range(3): for j in range(-2,-7,-2): var += 1 print(var) Sent from my iPhone -- https

RE: Friday Finking: Contorted loops

2021-09-13 Thread Avi Gross via Python-list
on.org Subject: Re: Friday Finking: Contorted loops On 2021-09-12 17:11:58 -0400, Avi Gross via Python-list wrote: > Yes, large units of code, and even smaller ones, may be a chore to > figure out. Arguably harder when you use indentation and the next/last > parts are not even on the same scr

Re: Friday Finking: Contorted loops

2021-09-13 Thread Peter J. Holzer
ILE clause controlling it at the end. > > do { # until the while clause below > > } while # End of the do loop. Because those comments don't tell me anything that I as a C programmer don't already know. Even though do/while loops are relatively rare, I've seen hundreds

Re: Friday Finking: Contorted loops

2021-09-12 Thread Alan Gauld via Python-list
On 12/09/2021 09:11, jak wrote: > if the only way to terminate a 'while True' loop is by using the 'break' > statement, why is it allowed to add the 'else' statement which will only > contain dead code? > > while True: > break > else: > print('dead code') > Because to the interpreter

RE: Friday Finking: Contorted loops

2021-09-12 Thread Avi Gross via Python-list
loop. My code tends to have brief comments especially when I have nested constructs such as multiple nested loops or in sequence, or if statements inside others. The comment often looks like ... # END of inner if ... # END of outer if The point is that places where the way of writing a program

Re: Friday Finking: Contorted loops

2021-09-12 Thread Peter J. Holzer
On 2021-09-12 10:28:22 -0700, 2qdxy4rzwzuui...@potatochowder.com wrote: > On 2021-09-11 at 18:21:17 +0100, > Alan Gauld via Python-list wrote: > > On 11/09/2021 15:41, Peter J. Holzer wrote: > > > How is C's do/while loop more horrible than Pascal's repeat/until? [...] > > so code that has > > >

RE: Friday Finking: Contorted loops

2021-09-12 Thread Avi Gross via Python-list
needs to do things in the current environment and thus only part of the functionality can be moved away. -Original Message- From: Python-list On Behalf Of Stefan Ram Sent: Saturday, September 11, 2021 10:56 PM To: python-list@python.org Subject: Re: Friday Finking: Contorted loops &quo

RE: Friday Finking: Contorted loops

2021-09-12 Thread Avi Gross via Python-list
The topic of looping and our current discussion stimulates me to ask if someone has categorized the uses of loops and it seems something obvious. Once you know what kinds of loopy looping there are, it can get easier to decide which, if any, of the methods to set up a loop make more sense

Re: Friday Finking: Contorted loops

2021-09-12 Thread 2QdxY4RzWzUUiLuE
On 2021-09-11 at 18:21:17 +0100, Alan Gauld via Python-list wrote: > On 11/09/2021 15:41, Peter J. Holzer wrote: > > > How is C's do/while loop more horrible than Pascal's repeat/until? > > Because it is very hard to spot or distinguish from a normal > while loop. > > while condition ; > > I

Re: Friday Finking: Contorted loops

2021-09-12 Thread jak
ss! -Original Message- From: Python-list On Behalf Of Alan Gauld via Python-list Sent: Saturday, September 11, 2021 3:59 AM To: python-list@python.org Subject: Re: Friday Finking: Contorted loops On 10/09/2021 19:49, Stefan Ram wrote: Alan Gauld writes: OK, That's a useful persp

Re: Friday Finking: Contorted loops

2021-09-12 Thread alister via Python-list
On Sun, 12 Sep 2021 10:11:15 +0200, jak wrote: > -- snip -- >> >> An inconsistency that I have been able to notice is this: >> someone suggests to remedy the absence of the do-while with: >> while True: >> ... >> if condition: >> break >> the problem arises if the while has

Re: Friday Finking: Contorted loops

2021-09-12 Thread Joe Pfeiffer
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Alan Gauld writes: >>OK, That's a useful perspective that is at least consistent. >>Unfortunately it's not how beginners perceive it > ... > > Beginners perceive it the way it is explained to them by > their teacher. My life as a professor would

Re: Friday Finking: Contorted loops

2021-09-12 Thread jak
-- snip -- An inconsistency that I have been able to notice is this: someone suggests to remedy the absence of the do-while with: while True: ... if condition: break the problem arises if the while has an else of its own because the break not only blocks the while loop but

Re: Friday Finking: Contorted loops

2021-09-12 Thread Alan Gauld via Python-list
ction of small C programs of mine I find: > > 35 regular for loops > 28 while loops > 2 infinite for loops > 1 "infinite" for loop (i.e. it exits somewhere in the middle) > 0 do/while loops. That wouldn't surprise me, I've only used do/while in C a handful o

Re: Friday Finking: Contorted loops

2021-09-12 Thread Peter J. Holzer
On 2021-09-11 21:38:02 -0400, Avi Gross via Python-list wrote: > Peter, in your own personal finite sample, I am wondering what you might do > TODAY if you looked at your loops again and considered redoing them for an > assortment of reasons ranging from using the code for teaching to e

RE: Friday Finking: Contorted loops

2021-09-11 Thread Avi Gross via Python-list
Peter, in your own personal finite sample, I am wondering what you might do TODAY if you looked at your loops again and considered redoing them for an assortment of reasons ranging from using the code for teaching to efficiency to just fitting your mood better? I have seen seasoned authors go

RE: Friday Finking: Contorted loops

2021-09-11 Thread Avi Gross via Python-list
n Behalf Of Alan Gauld via Python-list Sent: Saturday, September 11, 2021 3:59 AM To: python-list@python.org Subject: Re: Friday Finking: Contorted loops On 10/09/2021 19:49, Stefan Ram wrote: > Alan Gauld writes: >> OK, That's a useful perspective that is at least consistent. >>

Re: Friday Finking: Contorted loops

2021-09-11 Thread Alan Gauld via Python-list
On 10/09/2021 19:49, Stefan Ram wrote: > Alan Gauld writes: >> OK, That's a useful perspective that is at least consistent. >> Unfortunately it's not how beginners perceive it > ... > > Beginners perceive it the way it is explained to them by > their teacher. I'm not sure that's true. Most

Re: Friday Finking: Contorted loops

2021-09-11 Thread Peter J. Holzer
y empirical evidence to support this? > Or is it just a case of using the tools that are available? > In my experience of using Pascal (and much later with Delphi) > that I used repeat loops at least as often as while loops, > possibly more. > > But using Python and to a lesser exten

Re: Friday Finking: Contorted loops

2021-09-10 Thread Joe Pfeiffer
2qdxy4rzwzuui...@potatochowder.com writes: > On 2021-09-10 at 15:08:19 -0600, > Joe Pfeiffer wrote: > >> r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> > The existence of statements like "break" renders >> > proof techniques for loops (suc

Re: Friday Finking: Contorted loops

2021-09-10 Thread Terry Reedy
On 9/10/2021 7:38 AM, Alan Gauld via Python-list wrote: But python complicates this tenet still further by adding an else clause to its loops. And complicating this still more is that these else clauses have almost exactly opposite effects. To the contrary... if...else executes the else part

Re: Friday Finking: Contorted loops

2021-09-10 Thread 2QdxY4RzWzUUiLuE
On 2021-09-10 at 15:08:19 -0600, Joe Pfeiffer wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > > The existence of statements like "break" renders > > proof techniques for loops (such as Hoare's) with > > their invariants and inference rules u

RE: Friday Finking: Contorted loops

2021-09-10 Thread Avi Gross via Python-list
ally there is if not for the convoluted code to avoid it. Similarly, can most "while" loops that you want to be "until" loops not be made with a bit of code? I mean set first_time to True before starting. Set your while condition to while first_time OR condition or some othe

RE: Friday Finking: Contorted loops

2021-09-10 Thread Avi Gross via Python-list
over and over for "if" statements and perhaps some kind of case/switch statement and while loops and so on, may be parsimonious but ... -Original Message- From: Python-list On Behalf Of Alan Gauld via Python-list Sent: Friday, September 10, 2021 11:58 AM To: python-list@pytho

Re: Friday Finking: Contorted loops

2021-09-10 Thread Joe Pfeiffer
should always be on the watch when reading source code >>of a language like Python than relying only on the condition >>behind the "while". > > The existence of statements like "break" renders > proof techniques for loops (such as Hoare's

Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
On 10/09/2021 16:36, MRAB wrote: >> while...else... >> >> executes the else if the body of the loop does NOT get executed. >> >> for...else... >> >> executes the else iff ALL iterations of the for loop DO complete. >> > [snip] > > In both cases, it executes the 'else' part if it didn't break out

Re: Friday Finking: Contorted loops

2021-09-10 Thread MRAB
nature (or should be!) As such they can arguably be excused from the SP strictures. But python complicates this tenet still further by adding an else clause to its loops. And complicating this still more is that these else clauses have almost exactly opposite effects. while...else... executes the

Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
are available? In my experience of using Pascal (and much later with Delphi) that I used repeat loops at least as often as while loops, possibly more. But using Python and to a lesser extent C (which has a rather horrible do/while) construct I use while loops (often with an if-break) simply because tha

Re: Friday Finking: Contorted loops

2021-09-10 Thread Alan Gauld via Python-list
guably be excused from the SP strictures. But python complicates this tenet still further by adding an else clause to its loops. And complicating this still more is that these else clauses have almost exactly opposite effects. while...else... executes the else if the body of the loop does NOT get

Re: Friday Finking: Contorted loops

2021-09-10 Thread Greg Ewing
On 10/09/21 11:47 am, Terry Reedy wrote: 2. It is rare useful.  For loops are common.  While loops are occasional (nearly an order of magnitude less common than for loops.  Fractional loop constructs are rare. I would say that fractional loops are more common than loops which truly need to

Re: Friday Finking: Contorted loops

2021-09-09 Thread Dennis Lee Bieber
On Thu, 09 Sep 2021 19:07:49 -0400, Dennis Lee Bieber declaimed the following: >On Fri, 10 Sep 2021 09:36:36 +1200, dn via Python-list > declaimed the following: Someone, please shoot me now... >>This is a perennial question (one contributor calling it "immemorial"), >>but there seem to

Re: Friday Finking: Contorted loops

2021-09-09 Thread 2QdxY4RzWzUUiLuE
On 2021-09-09 at 22:33:16 +, Stefan Ram wrote: > One can think of a language where every loop is exited this > way, the only loop construct would be > > loop > ... > > and it would /always/ have to be exited via enclosed breaks. I'm not quite sure what you mean by "one can," but

Re: Friday Finking: Contorted loops

2021-09-09 Thread Dennis Lee Bieber
he SP constructs. A form of >case/select is expected in v3.10. The continuing omission is repeat-until. > > >If you have not met such a code-component before, the idea of a >repeat...until (or do...until) might look like this: > >repeat: >code-suite >until

Re: Friday Finking: Contorted loops

2021-09-09 Thread Terry Reedy
On 9/9/2021 5:36 PM, dn via Python-list wrote: Why does Python not have a repeat-until loop construct? 1. It is not needed. You covered that. 2. It is rare useful. For loops are common. While loops are occasional (nearly an order of magnitude less common than for loops. Fractional loop

Friday Finking: Contorted loops

2021-09-09 Thread dn via Python-list
such a code-component before, the idea of a repeat...until (or do...until) might look like this: repeat: code-suite until condition Thus, the code-suite will be executed as many times as necessary, until the condition is met. In Python, we are used to while-loops, which can

Re: on the popularity of loops while and for

2021-09-04 Thread Hope Rouselle
t; included in a standard installation of Python 3.9.6, say --- to see >> > which loops are more often used among while and for loops. Of course, >> > since English use the preposition ``for'' a lot, that makes my life >> > harder. Removing comments is easy, but r

Re: on the popularity of loops while and for

2021-09-04 Thread Peter J. Holzer
On 2021-08-29 10:04:47 +0100, Barry wrote: > > I'd like get a statistic of how often each loop is used in practice. > > > > I was trying to take a look at the Python's standard libraries --- those > > included in a standard installation of Python 3.9.6, say -

Re: on the popularity of loops while and for

2021-09-02 Thread Hope Rouselle
Terry Reedy writes: > On 8/28/2021 9:31 AM, Hope Rouselle wrote: >> I'd like get a statistic of how often each loop is used in practice. > > My guess is that for loops are at least twice as common as while loops. Scanning just the Python 3.9.6's Lib/ directory --- usi

Re: on the popularity of loops while and for

2021-09-02 Thread Hope Rouselle
standard installation of Python 3.9.6, say --- to see >> which loops are more often used among while and for loops. Of course, >> since English use the preposition ``for'' a lot, that makes my life >> harder. Removing comments is easy, but removing strings is harder.

Re: on the popularity of loops while and for

2021-09-02 Thread Hope Rouselle
d installation of Python 3.9.6, say --- to see >> which loops are more often used among while and for loops. Of course, >> since English use the preposition ``for'' a lot, that makes my life >> harder. Removing comments is easy, but removing strings is harder. So >

Re: on the popularity of loops while and for

2021-08-29 Thread Barry
 > On 28 Aug 2021, at 22:42, Hope Rouselle wrote: > > I'd like get a statistic of how often each loop is used in practice. > > I was trying to take a look at the Python's standard libraries --- those > included in a standard installation of Python 3.9.6, say

Re: on the popularity of loops while and for

2021-08-28 Thread Stestagg
On Sun, 29 Aug 2021 at 00:04, Stefan Ram wrote: > Stestagg writes: > >If you're doing this analysis, I'd be pretty interested in how many of > >those while loops where 'while True:' > > Here, about 40 %. Thanks! That's an interesting stat.

Re: on the popularity of loops while and for

2021-08-28 Thread Terry Reedy
On 8/28/2021 9:31 AM, Hope Rouselle wrote: I'd like get a statistic of how often each loop is used in practice. My guess is that for loops are at least twice as common as while loops. I was trying to take a look at the Python's standard libraries --- those included in a standard in

Re: on the popularity of loops while and for

2021-08-28 Thread Stestagg
If you're doing this analysis, I'd be pretty interested in how many of those while loops where 'while True:' I'd wager 75%. But may be completely off Steve On Sat, 28 Aug 2021 at 23:03, Hope Rouselle wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >

Re: on the popularity of loops while and for

2021-08-28 Thread Hope Rouselle
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Hope Rouselle writes: >>Have you guys ever measured something like that in a casual or serious > > import ast > import pathlib > rootname=r'' > rootpath=pathlib.Path(rootname) > rootiterable=rootpath.glob('**/*.py') > first = True > WhileCount =

Re: on the popularity of loops while and for

2021-08-28 Thread Chris Angelico
On Sun, Aug 29, 2021 at 7:40 AM Hope Rouselle wrote: > > I'd like get a statistic of how often each loop is used in practice. > > I was trying to take a look at the Python's standard libraries --- those > included in a standard installation of Python 3.9.6, say --- to s

on the popularity of loops while and for

2021-08-28 Thread Hope Rouselle
I'd like get a statistic of how often each loop is used in practice. I was trying to take a look at the Python's standard libraries --- those included in a standard installation of Python 3.9.6, say --- to see which loops are more often used among while and for loops. Of course, sin

Multiple event loops within the same thread ?

2020-06-14 Thread J. Pic
Hi all, It's possible to create several event loops in the same thread by calling asyncio.new_event_loop() Question: is there any use case where that could be useful ? Thank you in advance -- ∞ -- https://mail.python.org/mailman/listinfo/python-list

Re: Generators, generator expressions, and loops

2018-11-18 Thread David Neil
r = genders_array( index ); use this_loops_gender. To directly answer the narrow coding-question posed: in Python one achieves "counting loops" using a while-construct, eg count = 0 #or start-value while ( count < maximum ): etc count += 1

Re: Re: Generators, generator expressions, and loops

2018-11-16 Thread Peter via Python-list
(): ... More elegant are generator expressions but I cannot think of a way without giving an upper limit: for i in (2 ** i for i in range(100)): ... which looks ugly. Also, the double for-loop (and also the two loops in the above exmaple, for + while in the generator) look unnatural

Re: Generators, generator expressions, and loops

2018-11-16 Thread Matt Wheeler
> On 16 Nov 2018, at 14:54, Steve Keller wrote: > More elegant are generator expressions but I cannot think of a way > without giving an upper limit: > >for i in (2 ** i for i in range(100)): >... > > which looks ugly. Also, the double for-loop (and

Re: Generators, generator expressions, and loops

2018-11-16 Thread Santiago Basulto
Try itertools.count() . On Fri, Nov 16, 2018 at 12:08 PM Steve Keller wrote: > Cancel ill-formated article > -- > https://mail.python.org/mailman/listinfo/python-list > -- Santiago Basulto.- Co-founder @ rmotr.com -- https://m

Re: Generators, generator expressions, and loops

2018-11-16 Thread Ian Kelly
(): > ... > > More elegant are generator expressions but I cannot think of a way > without giving an upper limit: > > for i in (2 ** i for i in range(100)): > ... > > which looks ugly. Also, the double for-loop (and also the two loops > in the

Generators, generator expressions, and loops

2018-11-16 Thread Steve Keller
Cancel ill-formated article -- https://mail.python.org/mailman/listinfo/python-list

Generators, generator expressions, and loops

2018-11-16 Thread Steve Keller
range(100)): ... which looks ugly. Also, the double for-loop (and also the two loops in the above exmaple, for + while in the generator) look unnatural, somehow, i.e. loop over all elements which are created by a loop. Is there a more beautyful way? Steve -- https://mail.python.org

Generators, generator expressions, and loops

2018-11-16 Thread Steve Keller
range(100)): ... which looks ugly. Also, the double for-loop (and also the two loops in the above exmaple, for + while in the generator) look unnatural, somehow, i.e. loop over all elements which are created by a loop. Is there a more beautyful way? Steve -- https://mail.python.org

Re: clever exit of nested loops

2018-09-27 Thread Gregory Ewing
Neal Becker wrote: but it does violate the principle "Exceptions should be used for exceptional conditions). Python doesn't really go in for that philosophy. Exceptions are often used for flow control, e.g. StopIteration. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: clever exit of nested loops

2018-09-27 Thread Thomas Jollans
On 2018-09-26 21:06, Mark Lawrence wrote: > > To me the Ned Batchelder presentation > https://www.youtube.com/watch?v=EnSu9hHGq5o "Loop like a Native" is the > definitive way on how to deal with loops in Python. > Hear, hear. Great talk. -- https://mail.python.org/mailman/listinfo/python-list

Re: clever exit of nested loops

2018-09-27 Thread Neal Becker
Christian Gollwitzer wrote: > Am 26.09.18 um 12:28 schrieb Bart: >> On 26/09/2018 10:10, Peter Otten wrote: >>> class Break(Exception): >>> pass >>> >>> try: >>> for i in range(10): >>> print(f'i: {i}') >>> for j in range(10): >>> print(f'\tj: {j}') >>> for k in range(10): >>> print(f'\t\tk: {k}')

Re: clever exit of nested loops

2018-09-27 Thread Christian Gollwitzer
Am 26.09.18 um 12:28 schrieb Bart: On 26/09/2018 10:10, Peter Otten wrote: class Break(Exception): pass try: for i in range(10): print(f'i: {i}') for j in range(10): print(f'\tj: {j}') for k in range(10):   

Re: clever exit of nested loops

2018-09-27 Thread John Ladasky
On Wednesday, September 26, 2018 at 12:50:20 AM UTC-7, vito.d...@gmail.com wrote: > I have "abused" the "else" clause of the loops to makes a break "broke" more > loops I did this once upon a time. In recent years, when I start writing tricky nested loop

Re: clever exit of nested loops

2018-09-26 Thread Mark Lawrence
On 26/09/18 08:50, vito.detul...@gmail.com wrote: Hi Today I've added a couple of lines in my source code, and I'm very ashamed of it. it "runs", and I know what it does (for now), but it's "too clever". I have "abused" the "else" c

Re: clever exit of nested loops

2018-09-26 Thread Peter Otten
vito.detul...@gmail.com wrote: > Hi > Today I've added a couple of lines in my source code, and I'm very ashamed > of it. it "runs", and I know what it does (for now), but it's "too > clever". I have "abused" the "else" clause o

Re: clever exit of nested loops

2018-09-26 Thread Chris Angelico
On Wed, Sep 26, 2018 at 5:56 PM wrote: > > Hi > Today I've added a couple of lines in my source code, and I'm very ashamed of > it. > it "runs", and I know what it does (for now), but it's "too clever". > I have "abused" the &q

clever exit of nested loops

2018-09-26 Thread vito . detullio
Hi Today I've added a couple of lines in my source code, and I'm very ashamed of it. it "runs", and I know what it does (for now), but it's "too clever". I have "abused" the "else" clause of the loops to makes a break "broke&

Re: For next loops

2018-07-23 Thread Neil Cerutti
On 2018-07-23, no@none.invalid wrote: > never mind. > x = range (5) > y = range (5) > for ply in x: > > for com in y: > if ply==com: > result="Tie" > > print(ply,com,result) > result = "" Something like this is possible. "x", "y" and "result" can be unecess

Re: For next loops

2018-07-23 Thread Brian Oney via Python-list
What if ply != com in the first (0th) iteration?  It's better to have an 'else:'-statement in your case, I suppose. -- https://mail.python.org/mailman/listinfo/python-list

Re: For next loops

2018-07-22 Thread Ben Finney
no@none.invalid writes: > never mind. Congratulations for working out the error. And thank you for returning to show the corrected code :-) -- \ “If you don't know what your program is supposed to do, you'd | `\ better not start writing it.” —Edsger W. Dijkstra | _o__)

For next loops

2018-07-22 Thread no
x = range (5) y = range (5) for ply in x: for com in y: if ply==com: result="Tie" print(ply,com,result) Why is ply always equal to com? 0 0 Tie 0 1 Tie 0 2 Tie 0 3 Tie 0 4 Tie 1 0 Tie 1 1 Tie 1 2 Tie 1 3 Tie 1 4 Tie 2 0 Tie 2 1 Tie 2 2 Tie 2 3 Tie 2 4 Tie 3 0 Tie 3

Re: For next loops

2018-07-22 Thread no
never mind. x = range (5) y = range (5) for ply in x: for com in y: if ply==com: result="Tie" print(ply,com,result) result = "" On Sun, 22 Jul 2018 23:17:24 -0400, no@none.invalid wrote: >x = range (5) >y = range (5) >for ply in x: >for com in y: >

Re: number of loops

2018-03-17 Thread Michael F. Stemper
On 2018-03-15 08:28, michealmanc...@gmail.com wrote: I would like to have this offer 6 guesses, but instead it gives one guess and prints the if statement/output 6 timesany ideas where I went wrong? It sounds as if you'd like to have it making the offer within the loop rather than before t

Re: number of loops

2018-03-15 Thread Dan Stromberg
On Thu, Mar 15, 2018 at 8:25 AM, Bob Gailer wrote: > On Mar 15, 2018 9:30 AM, wrote: >> >> I would like to have this offer 6 guesses, but instead it gives one guess > and prints the if statement/output 6 timesany ideas where I went wrong? > > I suggest you conduct a walk-through. That means p

Re: number of loops

2018-03-15 Thread Bob Gailer
On Mar 15, 2018 9:30 AM, wrote: > > I would like to have this offer 6 guesses, but instead it gives one guess and prints the if statement/output 6 timesany ideas where I went wrong? I suggest you conduct a walk-through. That means pointing using a pencil or a mouse pointer at each statement a

number of loops

2018-03-15 Thread michealmancini
I would like to have this offer 6 guesses, but instead it gives one guess and prints the if statement/output 6 timesany ideas where I went wrong? import random number_of_guesses = 0 print ('Hello! what is your name?') my_name=input() print (my_name + " " + 'sounds like the name of my next

Unusual reactions (Was: .Re: Using Loops to track user input)

2017-04-20 Thread Jan van den Broek
On 2017-04-20, Robert L. wrote: Two things: - There's a '.' in front of "Re". - There's no "References"-header in your messages, this may confuse some newsreaders. -- Jan v/d Broek balgl...@dds.nl -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested for loops and print statements

2016-09-28 Thread Larry Hudson via Python-list
On 09/27/2016 09:20 PM, Steven D'Aprano wrote: On Wednesday 28 September 2016 12:48, Larry Hudson wrote: As they came through in the newsgroup, BOTH run correctly, because both versions had leading spaces only. (I did a careful copy/paste to check this.) Copying and pasting from the news clie

  1   2   3   4   5   6   7   8   9   10   >