Re: on writing a while loop for rolling two dice

2021-08-29 Thread dn via Python-list
On 30/08/2021 00.47, Peter Otten wrote: > On 29/08/2021 12:13, dn via Python-list wrote: >> On 29/08/2021 20.06, Peter Otten wrote: >> ... >>> OK, maybe a bit complicated... but does it pay off if you want to >>> generalize? >>> >> def roll_die(faces): >>>  while True: yield random.randrang

Re: PEP Idea: Real private attribute

2021-08-29 Thread Mehrzad Saremi
The proposed semantics would be the same as self.__privs__[__class__, "foo"]; yes I can say the problem is ugliness. The following is an example where name mangling can be problematic (of course there are workarounds, yet if double-underscores are meant to represent class-specific members, the foll

Re: on writing a while loop for rolling two dice

2021-08-29 Thread Chris Angelico
On Mon, Aug 30, 2021 at 9:53 AM dn via Python-list wrote: > > On 29/08/2021 22.24, Chris Angelico wrote: > > On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list > > wrote: > >> Efficiency: > >> - wonder how max( d ) == min( d ) compares for speed with the set() type > >> constructor? > > > > That

Re: on writing a while loop for rolling two dice

2021-08-29 Thread dn via Python-list
On 29/08/2021 22.24, Chris Angelico wrote: > On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list > wrote: >> Efficiency: >> - wonder how max( d ) == min( d ) compares for speed with the set() type >> constructor? > > That may or may not be an improvement. > >> - alternately len( d ) < 2? >> - or

Re: PEP Idea: Real private attribute

2021-08-29 Thread Chris Angelico
On Mon, Aug 30, 2021 at 5:49 AM Mehrzad Saremi wrote: > > No, a class ("the class that I'm lexically inside") cannot be accessed from > outside of the class. This is why I'm planning to offer it as a core > feature because only the parser would know. There's apparently no elegant > solution if you

Re: PEP Idea: Real private attribute

2021-08-29 Thread Mehrzad Saremi
No, a class ("the class that I'm lexically inside") cannot be accessed from outside of the class. This is why I'm planning to offer it as a core feature because only the parser would know. There's apparently no elegant solution if you want to implement it yourself. You'll need to write self.__privs

Re: Making command-line args available to deeply-nested functions

2021-08-29 Thread George Fischhof
Loris Bennett ezt írta (időpont: 2021. aug. 26., Cs, 16:02): > George Fischhof writes: > > [snip (79 lines)] > > >> > Hi, > >> > > >> > Also you can give a try to click and / or typer packages. > >> > Putting args into environment variables can be a solution too > >> > All of these depends on s

Re: code to initialize a sequence

2021-08-29 Thread Peter Otten
On 29/08/2021 20:44, joseph pareti wrote: In the code attached below, the A-variant is from somebody else who knows Python better than I. But I do not like to just use any code without having a grasp, specifically the line in* bold*, so I wrote the B-variant which gives the same results. The C-va

code to initialize a sequence

2021-08-29 Thread joseph pareti
In the code attached below, the A-variant is from somebody else who knows Python better than I. But I do not like to just use any code without having a grasp, specifically the line in* bold*, so I wrote the B-variant which gives the same results. The C-variant is identical to A and is there for ver

Re: on writing a while loop for rolling two dice

2021-08-29 Thread Peter Otten
On 29/08/2021 12:13, dn via Python-list wrote: On 29/08/2021 20.06, Peter Otten wrote: ... OK, maybe a bit complicated... but does it pay off if you want to generalize? def roll_die(faces): while True: yield random.randrange(1, 1 + faces) def hmt(faces, dies): for c, d in enumera

Re: on writing a while loop for rolling two dice

2021-08-29 Thread Chris Angelico
On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list wrote: > Efficiency: > - wonder how max( d ) == min( d ) compares for speed with the set() type > constructor? That may or may not be an improvement. > - alternately len( d ) < 2? > - or len( d ) - 1 coerced to a boolean by the if? Neither of t

Re: on writing a while loop for rolling two dice

2021-08-29 Thread dn via Python-list
On 29/08/2021 20.06, Peter Otten wrote: ... > OK, maybe a bit complicated... but does it pay off if you want to > generalize? > def roll_die(faces): > while True: yield random.randrange(1, 1 + faces) > def hmt(faces, dies): > for c, d in enumerate(zip(*[roll_die(faces)]*dies), 1

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 --- to see > which loops are mor

Re: on writing a while loop for rolling two dice

2021-08-29 Thread Peter Otten
On 28/08/2021 14:00, Hope Rouselle wrote: def how_many_times(): x, y = 0, 1 c = 0 while x != y: c = c + 1 x, y = roll() return c, (x, y) --8<---cut here---end--->8--- Why am I unhappy? I'm wish I could confine x, y to the while loop. T