Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Don't hit the keys so hard, it hurts.


devel / comp.lang.python / on writing a while loop for rolling two dice

SubjectAuthor
* on writing a while loop for rolling two diceHope Rouselle
+* Re: on writing a while loop for rolling two diceStefan Ram
|`* Re: on writing a while loop for rolling two diceHope Rouselle
| +* Re: on writing a while loop for rolling two diceHope Rouselle
| |+* Re: on writing a while loop for rolling two diceStefan Ram
| ||`- Re: on writing a while loop for rolling two diceHope Rouselle
| |+- Re: on writing a while loop for rolling two diceAlan Gauld
| |`- RE: on writing a while loop for rolling two diceAvi Gross
| `* Re: on writing a while loop for rolling two dicedn
|  `* Re: on writing a while loop for rolling two diceHope Rouselle
|   +* Re: on writing a while loop for rolling two diceChris Angelico
|   |`* Re: on writing a while loop for rolling two diceHope Rouselle
|   | `* Re: on writing a while loop for rolling two diceMichael F. Stemper
|   |  +- Re: on writing a while loop for rolling two diceHope Rouselle
|   |  +- Re: on writing a while loop for rolling two diceDennis Lee Bieber
|   |  `* RE: on writing a while loop for rolling two diceAvi Gross
|   |   +* Re: on writing a while loop for rolling two diceStefan Ram
|   |   |+* Re: on writing a while loop for rolling two diceGrant Edwards
|   |   ||+* Re: on writing a while loop for rolling two dicealister
|   |   |||+- RE: on writing a while loop for rolling two diceAvi Gross
|   |   |||+- Re: on writing a while loop for rolling two diceRichard Damon
|   |   |||`- RE: on writing a while loop for rolling two diceAvi Gross
|   |   ||+- Re: on writing a while loop for rolling two diceHope Rouselle
|   |   ||`* Re: on writing a while loop for rolling two diceGreg Ewing
|   |   || +* RE: on writing a while loop for rolling two diceAvi Gross
|   |   || |`* Re: on writing a while loop for rolling two dicecharles hottel
|   |   || | +- Re: on writing a while loop for rolling two diceGrant Edwards
|   |   || | +- Re: on writing a while loop for rolling two diceGrant Edwards
|   |   || | +- RE: on writing a while loop for rolling two diceAvi Gross
|   |   || | `- Re: on writing a while loop for rolling two diceDennis Lee Bieber
|   |   || `- Re: on writing a while loop for rolling two dicePeter J. Holzer
|   |   |+- Re: on writing a while loop for rolling two diceAlan Gauld
|   |   |+- Re: on writing a while loop for rolling two diceDennis Lee Bieber
|   |   |+- Re: on writing a while loop for rolling two diceGrant Edwards
|   |   |`- Re: on writing a while loop for rolling two diceDennis Lee Bieber
|   |   `- Re: on writing a while loop for rolling two diceGreg Ewing
|   `* Re: on writing a while loop for rolling two dicePeter J. Holzer
|    `- Re: on writing a while loop for rolling two diceHope Rouselle
+- Re: on writing a while loop for rolling two diceChris Angelico
+- Re: on writing a while loop for rolling two diceTerry Reedy
+- Re: on writing a while loop for rolling two dicePeter Otten
+- Re: on writing a while loop for rolling two dicedn
+- Re: on writing a while loop for rolling two diceChris Angelico
+- Re: on writing a while loop for rolling two dicePeter Otten
+- Re: on writing a while loop for rolling two dicedn
+- Re: on writing a while loop for rolling two diceChris Angelico
+- Re: on writing a while loop for rolling two dicedn
+* RE: on writing a while loop for rolling two diceDavid Raymond
|`* Re: on writing a while loop for rolling two diceHope Rouselle
| `* RE: on writing a while loop for rolling two diceAvi Gross
|  `* Re: on writing a while loop for rolling two diceStefan Ram
|   +- RE: on writing a while loop for rolling two diceAvi Gross
|   +- Re: on writing a while loop for rolling two dice2QdxY4RzWzUUiLuE
|   +- RE: on writing a while loop for rolling two diceAvi Gross
|   +- Non sequitur: on writing a while loop for rolling two diceDennis Lee Bieber
|   `- Non sequitur: on writing a while loop for rolling two diceDennis Lee Bieber
+* Re: on writing a while loop for rolling two diceChris Angelico
|`* Re: on writing a while loop for rolling two diceHope Rouselle
| `- Re: on writing a while loop for rolling two diceChris Angelico
+- Re: on writing a while loop for rolling two dicePeter Otten
+- Re: on writing a while loop for rolling two diceChris Angelico
+- Re: on writing a while loop for rolling two dicePeter Otten
+- Re: on writing a while loop for rolling two dicelucas
+- Re: on writing a while loop for rolling two dicedn
+- Re: on writing a while loop for rolling two diceChris Angelico
+* Re: on writing a while loop for rolling two dicedn
|`- Re: on writing a while loop for rolling two diceHope Rouselle
`- Re: on writing a while loop for rolling two diceAndrew Jaffe

Pages:123
on writing a while loop for rolling two dice

<86r1edlqxw.fsf@jevedi.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19180&group=comp.lang.python#19180

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!dsd0/0sLSmZ4OKvnSrnhDQ.user.46.165.242.75.POSTED!not-for-mail
From: hrouselle@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 09:00:27 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86r1edlqxw.fsf@jevedi.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="29910"; posting-host="dsd0/0sLSmZ4OKvnSrnhDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:f818RgTBM+8ecVteLVkJp6Y9+mI=
 by: Hope Rouselle - Sat, 28 Aug 2021 12:00 UTC

How should I write this? I'd like to roll two six-sided dice until I
get the same number on both. I'd like to get the number of times I
tried. Here's a primitive I'm using:

--8<---------------cut here---------------start------------->8---
>>> x, y = roll()
>>> x
6 >>> y
6 # lucky

>>> x, y = roll()
>>> x
4 >>> y
1 # unlucky
--8<---------------cut here---------------end--------------->8---

Here's my solution:

--8<---------------cut here---------------start------------->8---
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. The
introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
would you write this? Thank you!

Re: on writing a while loop for rolling two dice

<dice-20210828155623@ram.dialup.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19182&group=comp.lang.python#19182

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: 28 Aug 2021 14:57:38 GMT
Organization: Stefan Ram
Lines: 14
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <dice-20210828155623@ram.dialup.fu-berlin.de>
References: <86r1edlqxw.fsf@jevedi.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de /Rg/e8jV/h/yyrz1GgjhdARAzAB8oxr6XhR8xtqocQ9nP0
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 28 Aug 2021 14:57 UTC

Hope Rouselle <hrouselle@jevedi.com> writes:
>How would you write this?

"""Rolls two dice until both yield the same value.
Returns the number of times the two dice were rolled
and the final value yielded."""
roll_count = 0
while True:
outcome = roll_two_dice()
roll_count += 1
if outcome[ 0 ]== outcome[ 1 ]: break
return roll_count, outcome[ 0 ]

Re: on writing a while loop for rolling two dice

<86a6l1thz7.fsf@jevedi.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19184&group=comp.lang.python#19184

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!dsd0/0sLSmZ4OKvnSrnhDQ.user.46.165.242.75.POSTED!not-for-mail
From: hrouselle@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 17:46:52 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86a6l1thz7.fsf@jevedi.com>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="7444"; posting-host="dsd0/0sLSmZ4OKvnSrnhDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:f2Sx8ahbxowF3vqXXh2xCBap/v0=
 by: Hope Rouselle - Sat, 28 Aug 2021 20:46 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Hope Rouselle <hrouselle@jevedi.com> writes:
>>How would you write this?
>
> """Rolls two dice until both yield the same value.
> Returns the number of times the two dice were rolled
> and the final value yielded."""
> roll_count = 0
> while True:
> outcome = roll_two_dice()
> roll_count += 1
> if outcome[ 0 ]== outcome[ 1 ]: break
> return roll_count, outcome[ 0 ]

You totally convinced me. Thanks.

Re: on writing a while loop for rolling two dice

<861r6dthty.fsf@jevedi.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19185&group=comp.lang.python#19185

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!dsd0/0sLSmZ4OKvnSrnhDQ.user.46.165.242.75.POSTED!not-for-mail
From: hrouselle@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 17:50:01 -0300
Organization: Aioe.org NNTP Server
Message-ID: <861r6dthty.fsf@jevedi.com>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de>
<86a6l1thz7.fsf@jevedi.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="7444"; posting-host="dsd0/0sLSmZ4OKvnSrnhDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:M1esK5h75BV6b/DFBpqqO09k2fI=
 by: Hope Rouselle - Sat, 28 Aug 2021 20:50 UTC

Hope Rouselle <hrouselle@jevedi.com> writes:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> Hope Rouselle <hrouselle@jevedi.com> writes:
>>>How would you write this?
>>
>> """Rolls two dice until both yield the same value.
>> Returns the number of times the two dice were rolled
>> and the final value yielded."""
>> roll_count = 0
>> while True:
>> outcome = roll_two_dice()
>> roll_count += 1
>> if outcome[ 0 ]== outcome[ 1 ]: break
>> return roll_count, outcome[ 0 ]
>
> You totally convinced me. Thanks.

Wait, I'm surprised ``outcome'' is still a valid name at the
return-statement. Wasn't it defined inside the while? Shouldn't its
scope be restricted to the while block? I had no idea. I should learn
some Python.

Re: on writing a while loop for rolling two dice

<locals-20210828215916@ram.dialup.fu-berlin.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19186&group=comp.lang.python#19186

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: 28 Aug 2021 21:00:42 GMT
Organization: Stefan Ram
Lines: 23
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <locals-20210828215916@ram.dialup.fu-berlin.de>
References: <86r1edlqxw.fsf@jevedi.com> <dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com> <861r6dthty.fsf@jevedi.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de nmee3FhbxI7YrokvR9MCVwNIOL5syYOKLtQqq8u2pSzIMw
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 28 Aug 2021 21:00 UTC

Hope Rouselle <hrouselle@jevedi.com> writes:
>Wait, I'm surprised ``outcome'' is still a valid name at the
>return-statement. Wasn't it defined inside the while? Shouldn't its
>scope be restricted to the while block? I had no idea. I should learn
>some Python.

In Python, local names can be introduced by an assignment
and have function scope. There is no block scope in Python.

Below, "name" /is/ a local name already, but is being
used before being assigned to.

def function():
if False:
name = 0
return name

function()

# return name
# UnboundLocalError: local variable 'name' referenced before assignment

Re: on writing a while loop for rolling two dice

<86k0k5s1zt.fsf@jevedi.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19188&group=comp.lang.python#19188

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!dsd0/0sLSmZ4OKvnSrnhDQ.user.46.165.242.75.POSTED!not-for-mail
From: hrouselle@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 18:17:26 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86k0k5s1zt.fsf@jevedi.com>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de>
<86a6l1thz7.fsf@jevedi.com> <861r6dthty.fsf@jevedi.com>
<locals-20210828215916@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="30369"; posting-host="dsd0/0sLSmZ4OKvnSrnhDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:2IBMLc/wGhMWF657ZH30Kq3q6YU=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Hope Rouselle - Sat, 28 Aug 2021 21:17 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Hope Rouselle <hrouselle@jevedi.com> writes:
>>Wait, I'm surprised ``outcome'' is still a valid name at the
>>return-statement. Wasn't it defined inside the while? Shouldn't its
>>scope be restricted to the while block? I had no idea. I should learn
>>some Python.
>
> In Python, local names can be introduced by an assignment
> and have function scope. There is no block scope in Python.
>
> Below, "name" /is/ a local name already, but is being
> used before being assigned to.
>
> def function():
> if False:
> name = 0
> return name
>
> function()
>
> # return name
> # UnboundLocalError: local variable 'name' referenced before assignment

I appreciated the example. I had no idea. (I had looked up the rules
and it was pretty simple to understand, but an example is always nice.)
Thank you so much.

Re: on writing a while loop for rolling two dice

<mailman.481.1630186894.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19190&group=comp.lang.python#19190

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sun, 29 Aug 2021 07:41:21 +1000
Lines: 47
Message-ID: <mailman.481.1630186894.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<CAPTjJmrSbSe9wniFYcARh+DtZdUL7oH+ORpFataBNQUJa__a+w@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de rabWSWVjHn26/X/YlnrVIA349gSEq8Po0ZZqPmtsT7cw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=dG7W8dmv;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.008
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; 'returning':
0.07; 'sun,': 0.07; 'aug': 0.09; 'like,': 0.09; 'subject:two':
0.09; 'both.': 0.16; 'chrisa': 0.16; 'count.': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'received:209.85.166.53': 0.16; 'received:mail-
io1-f53.google.com': 0.16; 'solution:': 0.16; 'subject:loop':
0.16; 'subject:while': 0.16; 'subject:writing': 0.16; 'using:':
0.16; 'wrote:': 0.16; 'figure': 0.18; "i'd": 0.23; 'to:addr
:python-list': 0.23; '>>>': 0.26; 'this?': 0.28; "i'll": 0.28;
"i'm": 0.32; 'roll': 0.32; 'to:name:python': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'received:209.85.166': 0.33; 'header
:In-Reply-To:1': 0.33; 'subject:for': 0.33; 'same': 0.34;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'inside': 0.37; 'two': 0.37; 'received:209.85': 0.38;
'received:209': 0.38; 'could': 0.40; 'feel': 0.61; 'skip:h 10':
0.61; 'hope': 0.61; 'your': 0.64; 'let': 0.65; 'times': 0.66;
'wish': 0.66; 'lucky': 0.69; 'details.': 0.77; '2021': 0.84;
'want.': 0.84; 'trick': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=76gWwhAFUMnHfoKUEF7Wz1PkAaBXo9q/gbKyeZNWZok=;
b=dG7W8dmvcOwY8sIKivBL8rAGaCtRNIY8UOkTXDbNzuz9lhhh7LUOnTF16+bUAsGAv8
y8575I9r/x/al62ZCIctFhFN9NgVBIvJ2QMi/z3JqMRvbhSq/V4wEOU8JTzqkGBNnqqm
T6gybuRCdtaaUYQV4p0RcB4YgxMZn/hhxSM10/B48AwhPEnUIyu1z/Be0/8MMtH0KG+T
9qKmFHGmU56bOtWJSkKIDUM5NpQHopv1quqT73+gOJ9zKC2pPDgoNkxGjmw9BU7tE7zE
+7rKmJOoha8PiryNGEOlwigUgqg+0n/YpcqLtYTczlzQmqrOdGNCvuNPeoGePTclc52g
ChqA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=76gWwhAFUMnHfoKUEF7Wz1PkAaBXo9q/gbKyeZNWZok=;
b=IvCGtXQmlPG5qBu6XqSvBqSRiwIXWViP6rjn7LlXxI2/tG5n4cmPpeh0vQJcduTl4E
DGlAjyI2TQjkSjy1fsv3xwDzz72kJr/ijEXdVVrJVmNhEmVQHQPaqy3xFj7rbkJtAD3+
eM1JcHLN9n+vq0X9cgZLNv1AAqokBQYHihbCxIheJC721GzGshp6rg1POW2WdgPIRq16
NCMyKDnRuqYzBBuKb6r9W0SYGyhJ87rETR8QGleu9kPiKV55YDPVOaWjjL1NWvw5s6bA
8hWWA0/Yh63OIc4/aBMy74tf0Y7OgfJ34+x3K+nEo0u+zvBnwtzb/eHzSFmjZX12pKsD
sNfw==
X-Gm-Message-State: AOAM531QwVDZXmzFkp7XdJjQW+mxA50G+F4p9ZtP71La1eIfnZtyOTau
hPdTq0FFrvWejz2NebLvnYnINET715xZ123sG1GVnobYzDE=
X-Google-Smtp-Source: ABdhPJyySYmqFCOYvj2LQgd9F2tR5VgHIYoAFo34tV9/kcZ76ySUvm37FhLWfsrNUZPdFoxMOoaPpYnpdealE4rPais=
X-Received: by 2002:a5e:db06:: with SMTP id q6mr12665618iop.24.1630186891671;
Sat, 28 Aug 2021 14:41:31 -0700 (PDT)
In-Reply-To: <86r1edlqxw.fsf@jevedi.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrSbSe9wniFYcARh+DtZdUL7oH+ORpFataBNQUJa__a+w@mail.gmail.com>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
 by: Chris Angelico - Sat, 28 Aug 2021 21:41 UTC

On Sun, Aug 29, 2021 at 7:37 AM Hope Rouselle <hrouselle@jevedi.com> wrote:
>
> How should I write this? I'd like to roll two six-sided dice until I
> get the same number on both. I'd like to get the number of times I
> tried. Here's a primitive I'm using:
>
> --8<---------------cut here---------------start------------->8---
> >>> x, y = roll()
> >>> x
> 6
> >>> y
> 6 # lucky
>
> >>> x, y = roll()
> >>> x
> 4
> >>> y
> 1 # unlucky
> --8<---------------cut here---------------end--------------->8---
>
> Here's my solution:
>
> --8<---------------cut here---------------start------------->8---
> 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. The
> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
> would you write this? Thank you!

Your loop, fundamentally, is just counting. So let's just count.

def how_many_times():
for c in itertools.count():
...

Inside that loop, you can do whatever you like, including returning
immediately if you have what you want. I'll let you figure out the
details. :)

ChrisA

Re: on writing a while loop for rolling two dice

<mailman.485.1630190573.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19195&group=comp.lang.python#19195

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sun, 29 Aug 2021 10:42:28 +1200
Organization: DWM
Lines: 93
Message-ID: <mailman.485.1630190573.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com>
<4b8ed591-2f2f-6c76-4606-b431f52cf847@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de EctAgHtN8zso3BSUFYyxmgydRrx9/zTuS2k7oFTEQqOw==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=IV1mSOj5; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; 'improvement':
0.05; 'loop': 0.07; 'mechanism': 0.07; 'question:': 0.07;
'returning': 0.07; 'suggestion': 0.07; '=dn': 0.09; 'apparently':
0.09; 'from:addr:danceswithmice.info': 0.09;
'from:addr:pythonlist': 0.09; 'simplicity': 0.09; 'subject:two':
0.09; 'writes:': 0.09; '"what': 0.16; 'all)': 0.16; 'break,':
0.16; 'confusion.': 0.16; 'disconnected': 0.16; 'initiating':
0.16; 'message-id:@DancesWithMice.info': 0.16; 'purely': 0.16;
'range()': 0.16; 'received:51.254': 0.16; 'received:51.254.211':
0.16; 'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'result.': 0.16; 'solution:': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'whilst': 0.16; 'yield': 0.16; 'wrote:': 0.16; 'python':
0.16; 'returns': 0.23; 'to:addr:python-list': 0.23; 'idea': 0.25;
'>>>': 0.26; 'seems': 0.26; 'concept': 0.27; 'perform': 0.27;
'received:115': 0.27; 'this?': 0.28; '(and': 0.30; 'header:User-
Agent:1': 0.31; 'header:Organization:1': 0.31; 'seem': 0.31;
'but': 0.31; 'definitely': 0.31; "i'm": 0.32; 'concern': 0.32;
'outcome': 0.32; 'header:In-Reply-To:1': 0.33; 'subject:for':
0.33; 'hold': 0.34; 'same': 0.34; 'final': 0.36; 'two': 0.37;
'thanks.': 0.37; 'use': 0.38; 'does': 0.38; 'least': 0.40;
'necessary': 0.40; 'could': 0.40; 'completely': 0.60; 'potential':
0.61; 'skip:w 10': 0.61; 'feel': 0.61; 'skip:h 10': 0.61; 'hope':
0.61; 'remember': 0.61; 'to:': 0.62; 'skip:o 10': 0.62; 'me.':
0.62; 'true': 0.63; 'received:userid': 0.64; 'range': 0.64;
'thus': 0.65; 'times': 0.66; 'wish': 0.66; 'leading': 0.67;
'further': 0.68; 'within': 0.68; 'adds': 0.69; 'counter': 0.69;
'obvious': 0.69; 'deliver': 0.71; 'received:51': 0.77;
'received:localhost.localdomain': 0.77; 'received:localdomain':
0.81; '(like': 0.84; 'be!': 0.84; 'conflated': 0.84; 'counter.':
0.84; 'decent': 0.84; 'deem': 0.84; 'fuel': 0.84; 'motivated':
0.84; 'true:': 0.84; '"how': 0.91; 'trick': 0.91
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-5.0 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A autolearn=ham
autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 mail.rangi.cloud 6AAA8545F
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1630190564;
bh=ZrOrVMAcf+BLr/e2Fab4k+JjiSPBPt9cISZ4TynZds0=;
h=Subject:To:References:From:Date:In-Reply-To:From;
b=IV1mSOj5uGhvJ1oii3hi9rT1GYIMai/9TnGuP12z0bPmRMH7hfBnYbBMAwyjI1xZB
cN0syobYK/8hEunHkJEY0Ol+PLx95RihK8OSDHt7DvdC4rODCybcbI7ZnTg8nfKa6x
mVkQzg1/Rztnb0Sz/sQ4MegULz4LV/+S7Y62BzIisNxR5Q7AUh+UkgGRglL5i0Q9U8
6nYDMHpuuG5n0mcIvUC3xZ50Ibj2j0h/tOKfxIr5jB8w4LXJtvRqfzYKRYr5riCrkQ
W9T2x5osjX1ESaitV7Kx7zMyo7c4CYBNXW3o6g9eE1QnwFRri+CIqBHrzEy50pryq/
qnkCw04QIZHIQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <86a6l1thz7.fsf@jevedi.com>
Content-Language: en-GB
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <4b8ed591-2f2f-6c76-4606-b431f52cf847@DancesWithMice.info>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com>
 by: dn - Sat, 28 Aug 2021 22:42 UTC

On 29/08/2021 08.46, Hope Rouselle wrote:
> Here's my solution:
>
> --8<---------------cut here---------------start------------->8---
> def how_many_times():
> x, y = 0, 1
> c = 0
> while x != y:
> c = c + 1
> x, y = roll()
> return c, (x, y)

>
> Why am I unhappy? I'm wish I could confine x, y to the while loop. The
> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
> would you write this?

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> """Rolls two dice until both yield the same value.
>> Returns the number of times the two dice were rolled
>> and the final value yielded."""
>> roll_count = 0
>> while True:
>> outcome = roll_two_dice()
>> roll_count += 1
>> if outcome[ 0 ]== outcome[ 1 ]: break
>> return roll_count, outcome[ 0 ]
>
> You totally convinced me. Thanks.

On the other hand...
whilst you expressed concern about the apparently disconnected 'set up'
necessary before the loop, this solution adds a "True/Forever" and a
"Break" construct, which some may deem not that much better (if at all)

The idea of abrogating the while-condition but then adding another
(disconnected) condition to break, seems to hold equal potential for
confusion. or the type of dissatisfaction which motivated the original
question!

Looking at that from the inside-out, the loop's contents perform two
functions: the rolling and counting (per Statement of Requirements), but
also a loop-controlling element. Thus the reader's question: "what does
this loop do?" is conflated with "how many times does it do it?".

Let's go completely off-the-rails, why not use a never-ending range() to
fuel a for-loop 'counter', and within that loop perform the dice-roll(s)
and decide if it is time to 'break'. The range replaces the "True". The
for-loops index or 'counter' will deliver the desired result.

Neat? No!
Readable? No!
An improvement over the while-True? Definitely not!
Yet, the mechanism is the same AND offers a built-in counter. Hmmm...

Returning to the concern:

x, y = 0, 1
c = 0

The first line is purely to ensure that the loop executes at least once,
ie the two assigned-values are not 'real'. Hence the disquiet!

Initiating the counter is unavoidable (@Chris' suggestion notwithstanding).

However, remember that Python (like decent DBs) has a concept (and an
idiom) of a value to be used when we don't (yet) know what the value
is/should be! Further that Python allows such a value to be used in
comparisons:

>>> None != None
False
>>> None == None
True

Leading to:

c, x, y = 0, None, None
while ...

Which solution reverts to the original loop-contents. which seem more
obvious and thus more readable. (YMMV!)

Simplicity over 'being clever'...
--
Regards,
=dn

Re: on writing a while loop for rolling two dice

<mailman.487.1630191731.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19197&group=comp.lang.python#19197

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: tjreedy@udel.edu (Terry Reedy)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 18:00:49 -0400
Lines: 57
Message-ID: <mailman.487.1630191731.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<sgebmi$3f2$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de t+i0NGXAb/+lNOxzAierKgiDZf9LLBkKN05foG7EwrmA==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'loop': 0.07;
'message-id:@ciao.gmane.io': 0.09; 'received:ciao.gmane.io': 0.09;
'received:gmane.io': 0.09; 'received:list': 0.09; 'subject:two':
0.09; 'terry': 0.09; '8:00': 0.16; '>>>>': 0.16; 'both.': 0.16;
'from:addr:udel.edu': 0.16; 'impossible': 0.16;
'received:116.202': 0.16; 'received:116.202.254': 0.16;
'received:116.202.254.214': 0.16; 'solution:': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'using:': 0.16; 'wrote:': 0.16; "i'd": 0.23; 'to:addr
:python-list': 0.23; 'this?': 0.28; 'header:User-Agent:1': 0.31;
'am,': 0.31; "i'm": 0.32; 'roll': 0.32; 'header:In-Reply-To:1':
0.33; 'subject:for': 0.33; 'same': 0.34; '"the': 0.35; 'two':
0.37; 'something': 0.38; 'could': 0.40; 'feel': 0.61; 'skip:h 10':
0.61; 'hope': 0.61; 'times': 0.66; 'wish': 0.66; 'lucky': 0.69;
'received:116': 0.71; 'true:': 0.84; 'trick': 0.91
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <86r1edlqxw.fsf@jevedi.com>
Content-Language: en-US
X-Mailman-Approved-At: Sat, 28 Aug 2021 19:02:10 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgebmi$3f2$1@ciao.gmane.io>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
 by: Terry Reedy - Sat, 28 Aug 2021 22:00 UTC

On 8/28/2021 8:00 AM, Hope Rouselle wrote:
> How should I write this? I'd like to roll two six-sided dice until I
> get the same number on both. I'd like to get the number of times I
> tried. Here's a primitive I'm using:
>
> --8<---------------cut here---------------start------------->8---
>>>> x, y = roll()
>>>> x
> 6
>>>> y
> 6 # lucky
>
>>>> x, y = roll()
>>>> x
> 4
>>>> y
> 1 # unlucky
> --8<---------------cut here---------------end--------------->8---
>
> Here's my solution:
>
> --8<---------------cut here---------------start------------->8---
> 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. The
> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
> would you write this? Thank you!

Something like (untested)

c = 0
while True:
c += 1
x, y = roll()
if x == y:
return c, (x,y)

or even better to me, as it will not loop forever if you mess up the
condition

for i in range(1, 1000000):
x, y = roll()
if x == y:
return i, (x,y)
# return "The universe ends as the essentially impossible happened"

--
Terry Jan Reedy

Re: on writing a while loop for rolling two dice

<mailman.488.1630191731.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19198&group=comp.lang.python#19198

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: alan.gauld@yahoo.co.uk (Alan Gauld)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 23:51:44 +0100
Lines: 34
Message-ID: <mailman.488.1630191731.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com>
<861r6dthty.fsf@jevedi.com> <sgeem0$11fs$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 5B/AgwhzocmRKcTkvYra5ArSvRbMYVeItEDcalyfKgRQ==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'debug': 0.07; 'message-
id:@ciao.gmane.io': 0.09; 'readable': 0.09;
'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'subject:two': 0.09; '21:50,': 0.16;
'bugs': 0.16; 'declare': 0.16; 'flickr': 0.16;
'from:addr:alan.gauld': 0.16; 'from:name:alan gauld': 0.16;
'photo-blog': 0.16; 'received:116.202': 0.16;
'received:116.202.254': 0.16; 'received:116.202.254.214': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'url-ip:79.170.44.132/32': 0.16; 'url-ip:79.170.44/24':
0.16; 'url-ip:79.170/16': 0.16; 'url-ip:79/8': 0.16; 'url:alan-g':
0.16; 'url:alan_gauld': 0.16; 'url:alangauldphotos': 0.16;
'wrote:': 0.16; 'url:amazon': 0.20; "i'd": 0.23; 'to:addr:python-
list': 0.23; 'code': 0.24; '>>>': 0.26; "wasn't": 0.27; 'header
:User-Agent:1': 0.31; 'but': 0.31; "i'm": 0.32; 'outcome': 0.32;
'personally': 0.32; 'program': 0.33; 'header:In-Reply-To:1': 0.33;
'subject:for': 0.33; 'at:': 0.37; 'inside': 0.37; 'really': 0.37;
'author': 0.38; 'valid': 0.40; 'hope': 0.61; 'remember': 0.61;
'time.': 0.63; 'follow': 0.63; 'site': 0.69; 'url:author': 0.69;
'received:116': 0.71; 'surprised': 0.84; 'true:': 0.84; 'return.':
0.91
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
In-Reply-To: <861r6dthty.fsf@jevedi.com>
Content-Language: en-GB
X-Mailman-Approved-At: Sat, 28 Aug 2021 19:02:10 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgeem0$11fs$1@ciao.gmane.io>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com>
<861r6dthty.fsf@jevedi.com>
 by: Alan Gauld - Sat, 28 Aug 2021 22:51 UTC

On 28/08/2021 21:50, Hope Rouselle wrote:

>>> roll_count = 0
>>> while True:
>>> outcome = roll_two_dice()
>>> roll_count += 1
>>> if outcome[ 0 ]== outcome[ 1 ]: break
>>> return roll_count, outcome[ 0 ]
>>
>
> Wait, I'm surprised ``outcome'' is still a valid name at the
> return-statement. Wasn't it defined inside the while?

If that really bugs you just replace the break with the return.

>>> if outcome[ 0 ]== outcome[ 1 ]:
>>> return roll_count, outcome[ 0 ]

Now its all inside the loop.

But remember readable code is better than cute code every time.
And personally I'd just declare the x,y up front. Easier to
understand and debug IMHO.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

RE: on writing a while loop for rolling two dice

<mailman.491.1630196351.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19201&group=comp.lang.python#19201

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigross@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: RE: on writing a while loop for rolling two dice
Date: Sat, 28 Aug 2021 20:19:02 -0400
Lines: 88
Message-ID: <mailman.491.1630196351.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com>
<861r6dthty.fsf@jevedi.com> <sgeem0$11fs$1@ciao.gmane.io>
<012701d79c6b$786074e0$69215ea0$@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de E/GMIz0mOlw9je56thIMLQyALW0uFCVmUjN3cteSObsA==
Return-Path: <avigross@verizon.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=verizon.net header.i=@verizon.net header.b=eor3Gjvn;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'random':
0.05; 'variable': 0.05; 'debug': 0.07; 'loop': 0.07;
'url:mailman': 0.09; 'else:': 0.09; 'obviously': 0.09; 'output:':
0.09; 'overhead': 0.09; 'readable': 0.09; 'subject:two': 0.09;
'import': 0.14; '21:50,': 0.16; 'bugs': 0.16; 'declare': 0.16;
'declared': 0.16; 'flickr': 0.16; 'gauld': 0.16; 'iterative':
0.16; 'photo-blog': 0.16; 'received:(vzm hermes smtp server)':
0.16; 'subject:loop': 0.16; 'subject:while': 0.16;
'subject:writing': 0.16; 'url-ip:79.170.44.132/32': 0.16; 'url-
ip:79.170.44/24': 0.16; 'url-ip:79.170/16': 0.16; 'url-ip:79/8':
0.16; 'url:alan-g': 0.16; 'url:alan_gauld': 0.16;
'url:alangauldphotos': 0.16; 'wrote:': 0.16; 'url:listinfo': 0.16;
'url:amazon': 0.20; 'url-ip:188.166.95.178/32': 0.20; 'url-
ip:188.166.95/24': 0.20; 'version': 0.22; 'url-ip:188.166/16':
0.23; "i'd": 0.23; 'to:addr:python-list': 0.23; 'code': 0.24;
'>>>': 0.26; 'skip:- 10': 0.26; '11,': 0.27; 'first,': 0.27;
"wasn't": 0.27; 'single': 0.28; 'url-ip:188/8': 0.29; 'there':
0.31; 'but': 0.31; "i'm": 0.32; '13,': 0.32; 'encountered': 0.32;
'outcome': 0.32; 'personally': 0.32; 'python-list': 0.32;
'program': 0.33; 'using': 0.33; 'header:In-Reply-To:1': 0.33;
'subject:for': 0.33; 'at:': 0.37; 'inside': 0.37; 'two': 0.37;
'really': 0.37; 'author': 0.38; 'main': 0.40; 'valid': 0.40;
'hope': 0.61; 'remember': 0.61; 'skip:r 30': 0.61; 'here': 0.62;
'to:': 0.62; 'time.': 0.63; 'ever': 0.63; 'follow': 0.63; 'your':
0.64; 'skip:r 20': 0.64; 're:': 0.65; 'popular': 0.67; 'site':
0.69; 'and,': 0.69; 'counter': 0.69; 'generator': 0.69;
'received:74.6.130.42': 0.69;
'received:sonic308-3.consmr.mail.bf2.yahoo.com': 0.69;
'url:author': 0.69; 'sent:': 0.71; '2021': 0.84; '(first': 0.84;
'body:': 0.84; 'saturday,': 0.84; 'surprised': 0.84; 'true:':
0.84; 'return.': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1630196347; bh=tiR2nj9YrVmTaymTr9guQWOUCRj2RzRO3OLkI3rHIpM=;
h=From:To:References:In-Reply-To:Subject:Date:From:Subject:Reply-To;
b=eor3GjvnKwLrTqpAHCOdyVTrTEC26H2CWw6gFkMuglQMICH4Dp3YHmIqpcZWIQxWzZMX4ETIaYaKz2zXGIEEUyLyTAaSJ+o4/Z6azZyAekIUv8tPKRNFOpHpVs2/HYXDgcxNo8XEcNSKl3ZFVSP6O5+Qj5Z/1LxVzm/z/JVSyhbE/3Q67xQslSfctKor1fkmnfiCLq+hZ7PTCEKzOhume6namyxdlmAHDRGE3CMZeTAwyZS9TeMDNVZfsnbUZt+TYuFDdUHaOo39U/f0cMdwIbLBJsGUAN+bgJBtwtYJs9s8VkLZFI/SCjOVgziqrUVZ3H4y+6Ajk1IW4a4XiwQNjA==
X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048;
t=1630196347; bh=I0ZFInebynjYi+BQX9SsvZVH0e84/iSwMjzMGMGikYp=;
h=X-Sonic-MF:From:To:Subject:Date:From:Subject;
b=eeqLXZQEa5Q6UfotXMqWVELo401Bg6pkDGJjRHVFjf7H/eESbd84PrLEH8ZDc0WbycV9nHZPzcU+nl1bzolKSKoQ4p28c/uDgqXhIVv2z86bWRDtilmZ+/GRr7GMK3qGZcc5uyH+dXu8oWy3GxcjkC1u6NA84a1EJ3wBb+cLmAQkGoRYnfSn6tZeXsObxl0px1jHY1yuhjhs5tHJqYaM3GjsdTQ2K+KnO6evFQfU+32a2FQRPmaRQoZXHnWlX/83aUPPqMa6qX5rQ/Moddcvfl8p3nHKzJl8i9y8llmpBnKWrJv/iv/o6ypCtDyRQSnVCT9Le2++cao4su9naoIXmQ==
X-YMail-OSG: XnWqY1cVM1kFsOxiXp2qm3fhUVdZDhoKyU30Xsi4ep0Y_5PDvzJfrB9EHHnSiYg
stoGc0ZTy6037_s9w_PhLW9pKk_mXpKMb5fOaPBrjE_fsK1Bys2o8n5Nx2RV4PbXE.f9G5_euQic
mRzgbx0bweX.Wrz4Vg8ReignQ_hOs855yx8GVbTZJR6i8iIlFZpC3YpprtNEp0M4DIKS3K.BCmJw
eMiHq_q0jsOS5hlHEM5bu7B5HTwkONPx93gTrHYmDEErfnnUA11zNv2Q6M__v_ciwCmSbdXvpUys
3lS4_eGlxO130PlPfcP84ahvhW6cz5Gc2VGNj1Z9rvPzHmsK1yK_zpzZBe02VyUBG_kSI_GIKoyc
UNeyEYb2DOVjNDg3th9W5Kh7U78ksPdHymYlnAvvsgitVN4rvc2b6cEK38DdFbSNpDufj1D6bzcH
HNVhmzeNTiApybTtSVDrqABvOkWyuJv.MhBSQrCNrRdYXzbcEwvL1l9vmFy0JuyEkNoGJ2n9WAi6
FupHYsaBzLvOS_6BRVrtLUlEtMaFgcXbPmh1yjNuT6p5ngK515erO6Q.sR86aksn_qAWlbTIZ_JN
4jm8RYNXdtxWTg27a96e56hjJCr_CLC66hyL6EBM6cG7eSo7s8Y_wEO1LZBg0CkNL22S6P8mdhol
VzEBXS9Y5p4fSlrn4Ufyk5KE2Eev2UOT.zS16YYUWwZRVZHy_I0oMlx6dMWtva7kY.nahuD9pmhT
ZPP3eFkpmDzDcsj7a98vi7S9h0ef0ZZw18s9gYF.jWawa1CFRNC7svwp_bYuxOsSuiZb3411EXlw
HwgjYotxp4smfQOAR6LG4yiCQcnZWFzR7ng9FatDEG_dNdKV7Q4st105eDSSNvAl91mexIgfQPfj
8zhLNC6Lay.B3imzCqj.556GdzQcvxUO4s7NDsadgnPO_WZ1jJvZyr412DV9urCOnCIDP5czuc.e
j5CvvxRxVoGZKDCfwtbTPfdHZmNu2gka7_D4iRrfY4eQn6ZCty12TVxlHL6QcFemLD2JNw0CnVSD
f78ywpNDW0b.lpMCZgQL8r1q5jSV7oyjWZccGZNY6fCAmL83ywHkwQD9MMmwnP.o72uPiu019UiI
spE9vgPpLfMeL.XAEI70XAjJlFFjnJVcqqXs7wykUXov83__4fW9z7XfwtWfKfKb_7VWd1UYhWLC
S1a3t4DlesCaD7TQYt193u5ZFnZfrq0a5BTo9PtJ6oaOYcm1ed5uj2eGI0QMyFra7Q0V4S8ba1o2
cI1i.Dmh8k6mE1tim6sA1oImJ7.xpvcvysPiFrMYj7Wts4tFaEuemKmQqm6khv8KHsgmqTl4AJFJ
apvdcIOaOEtDpc6sOud6HwYm9VaB8_5EuQdzTdTGTXqv4wW4Ei9UskoWSNvQUq99QaRgMeUljUKq
jymVxS12esGRhYZz3pi9OUHPn11DtzntjZ4Oe2O1nWdeCwtfPMtYTatk.s4zYLr1y5cGbjXV2aRw
LPZja_I9uxSi1c1rMuoXoitf1R_p4UPkRnH3fjqjUjFpE6WIBFfRRz0nDI9PdTSSjyDoaYQ5z8Vt
TUNXp0k7hCSXF9_AtEToH3NLRkEnf8ctQDxwhWyqOdvTOM47jxPwTi9KKk_4iCmElVmoeO5b1LaA
hZjzEmcj0hRnoccsdFfrPbfOKQKz6DHJ46KxwqIBye0yeWi6Vp1Xqx886EVg_hW6JtLsgyU2LcNO
46K9z7BlJF4_rMOq4of6OeZY4bYMuglgVmkQUeHYegMNVa_NQ2zgWybYnqu9yoSWul_AVwNf58om
EhdLJgly8DuEMjmZQHQO92BdnA0mjpMLTvK_OypiJQO8hi4xMfl4l9WFFW88xkv7VS0sHNTm1c_p
E6GZ8jSzbKz3XTFoERpXympwV3BcTMPjEhi6DEfPwkzKCG5DotDBxlU2Uu_cjoWcdpG4Bl1vbCJI
uoeKST6Ua_ioVX1dY9LnRNKxq067NIgsIeu1sL6IxjYP1.zb7HlpgMlWYXOGnH7LGpr.FshEQ5bd
0M31gS7yp1Cl3FYJkTT2k.xOb91P0qK112dK7p026OCN6lnNlelnmdyWhFGyHlgsIkiuaQKSiNoG
lNvu4fL1Qbsx1ewmHkfL1GHqcwxdhtJJWo8cCrevvd1BNhG3kesj1cl1YJxEjE6ZNn84_WMvGESQ
aat_sO1XH_xxEq.k0OdKnHRc_r4lBGUmCLVeLfAbnykmGaKw.jPqDecLK6BU5_aWniM_GYgjtHPF
ciBy3S1xApEMYcq9II9u9jUOPU3UDMeb.8aJa3Yz90gzPNc.de1MIMSjZIKs.rA39tQ--
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <sgeem0$11fs$1@ciao.gmane.io>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQGJaWvPXwJqf5icjAQ/OktvdS4XLwJBtumuAlZstTgCHPEmUQIcvW/jq99wxUA=
Content-Language: en-us
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <012701d79c6b$786074e0$69215ea0$@verizon.net>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de> <86a6l1thz7.fsf@jevedi.com>
<861r6dthty.fsf@jevedi.com> <sgeem0$11fs$1@ciao.gmane.io>
 by: Avi Gross - Sun, 29 Aug 2021 00:19 UTC

And there is the ever popular recursive version you call with no while loop
in sight. And, oddly, no variable declared in your main body:

#---- CODE START ---
import random

def roll2():
return random.randint(1,6), random.randint(1,6)

def roll_equal(counter):
first, second = roll2()
encountered = counter + 1
if (first == second):
return(encountered)
else:
return(roll_equal(encountered))

#--- CODE END ---

Since the result is usually a single digit of iterations, no biggie. Here is
some output:

>>> roll_equal(0)
6 >>> roll_equal(0)
7 >>> roll_equal(0)
1 >>> roll_equal(0)
7 >>> roll_equal(0)
6 >>> [ roll_equal(0) for n in range(10)]
[3, 4, 2, 5, 8, 1, 1, 2, 3, 9]
>>> [ roll_equal(0) for n in range(10)]
[3, 3, 7, 19, 7, 2, 1, 3, 8, 4]
>>> [ roll_equal(0) for n in range(10)]
[1, 3, 1, 13, 11, 4, 3, 5, 2, 4]

And the code can be a tad shorter, LOL!

But obviously then you have more overhead than an iterative solution or one
using a generator ...

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Alan Gauld via Python-list
Sent: Saturday, August 28, 2021 6:52 PM
To: python-list@python.org
Subject: Re: on writing a while loop for rolling two dice

On 28/08/2021 21:50, Hope Rouselle wrote:

>>> roll_count = 0
>>> while True:
>>> outcome = roll_two_dice()
>>> roll_count += 1
>>> if outcome[ 0 ]== outcome[ 1 ]: break return roll_count,
>>> outcome[ 0 ]
>>
>
> Wait, I'm surprised ``outcome'' is still a valid name at the
> return-statement. Wasn't it defined inside the while?

If that really bugs you just replace the break with the return.

>>> if outcome[ 0 ]== outcome[ 1 ]:
>>> return roll_count, outcome[ 0 ]

Now its all inside the loop.

But remember readable code is better than cute code every time.
And personally I'd just declare the x,y up front. Easier to understand and
debug IMHO.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

--
https://mail.python.org/mailman/listinfo/python-list

Re: on writing a while loop for rolling two dice

<mailman.492.1630224460.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19202&group=comp.lang.python#19202

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: __peter__@web.de (Peter Otten)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sun, 29 Aug 2021 10:06:47 +0200
Lines: 60
Message-ID: <mailman.492.1630224460.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de TmM04VEdpkEwFNfXvP5kWQQQDt4vMZQtcdCqWpAvf7hw==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'random':
0.05; 'loop': 0.07; 'message-id:@ciao.gmane.io': 0.09; 'ok,':
0.09; 'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'subject:two': 0.09; 'import': 0.14; '(1,':
0.16; 'from:addr:web.de': 0.16; 'received:116.202': 0.16;
'received:116.202.254': 0.16; 'received:116.202.254.214': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'yield': 0.16; 'wrote:': 0.16; 'maybe': 0.20; "i'd": 0.23;
'to:addr:python-list': 0.23; 'probably': 0.24; '>>>': 0.26; 'bit':
0.28; 'this?': 0.28; 'header:User-Agent:1': 0.31; 'but': 0.31;
"i'm": 0.32; 'header:In-Reply-To:1': 0.33; 'subject:for': 0.33;
'does': 0.38; 'could': 0.40; 'feel': 0.61; 'skip:h 10': 0.61;
'hope': 0.61; 'pay': 0.64; 'wish': 0.66; 'skip:e 20': 0.70;
'received:116': 0.71; 'true:': 0.84; 'trick': 0.91
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <86r1edlqxw.fsf@jevedi.com>
Content-Language: en-US
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgff85$s6i$1@ciao.gmane.io>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
 by: Peter Otten - Sun, 29 Aug 2021 08:06 UTC

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. The
> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
> would you write this? Thank you!

I'd probably hide the while loop under the rug:

>>> import random
>>> def roll_die():
while True: yield random.randrange(1, 7)


Then:

>>> def hmt():
for c, (x, y) in enumerate(zip(roll_die(), roll_die()), 1):
if x == y:
return c, (x, y)


>>> hmt()
(1, (2, 2))
>>> hmt()
(4, (4, 4))
>>> hmt()
(1, (5, 5))

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):
if len(set(d)) == 1: return c, d


>>> hmt(10, 1)
(1, (2,))
>>> hmt(10, 2)
(3, (10, 10))
>>> hmt(10, 3)
(250, (5, 5, 5))
>>> hmt(1, 10)
(1, (1, 1, 1, 1, 1, 1, 1, 1, 1, 1))

You decide :)

Re: on writing a while loop for rolling two dice

<mailman.494.1630231999.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19204&group=comp.lang.python#19204

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sun, 29 Aug 2021 22:13:03 +1200
Organization: DWM
Lines: 35
Message-ID: <mailman.494.1630231999.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Qg6RCOdlYQ1gFfvZqFLemAP1btwHxInQlGePAS0JcdIw==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=mcqOkcdc; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; 'parameter':
0.05; '8bit%:62': 0.09; '=dn': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'ok,': 0.09; 'subject:two': 0.09; '>>>>': 0.16; 'basic,':
0.16; 'computers': 0.16; 'dies': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'simpler,':
0.16; 'subject:loop': 0.16; 'subject:while': 0.16;
'subject:writing': 0.16; 'yield': 0.16; 'wrote:': 0.16; 'maybe':
0.20; 'language': 0.22; 'to:addr:python-list': 0.23; 'bit': 0.28;
'header:User-Agent:1': 0.31; 'header:Organization:1': 0.31; 'but':
0.31; 'header:In-Reply-To:1': 0.33; 'subject:for': 0.33;
'running': 0.35; 'does': 0.38; 'english': 0.61; 'skip:\xc2 10':
0.62; 'pay': 0.64; 'received:userid': 0.64; 'thus': 0.65; 'speed':
0.69; 'reminder': 0.69; '8bit%:100': 0.75; 'die': 0.77;
'received:51': 0.77; 'received:localhost.localdomain': 0.77;
'....': 0.81; 'received:localdomain': 0.81; 'education:': 0.84;
'received:47': 0.84; 'system).': 0.84; 'true:': 0.84; 'hollywood':
0.93
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.6 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A autolearn=ham
autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 mail.rangi.cloud C1C284DC9
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1630231996;
bh=/Iy24ysUwgVwZmBNNGotxowyFlhyTnD7yVmp+G7+RR4=;
h=Subject:To:References:From:Date:In-Reply-To:From;
b=mcqOkcdcJkO9g7vCLG1oohJEQaBd33hN8W0dOclCfVtd5w0WDUj2B2j6QDyzgTYPt
jq3x+rmiyoBpeveicKviQ9W4G4LBJIoUVKyyMfgz1YP4yTP8z6/PaME1F0jXhvhnPr
eyjTF+b7gYe8Ht8EQBNQQ00K+Us4fSALkyz7V2MnowWRa6xBUv/Q5smsBpnyZgPD9f
H3QR+N7/WsVGgbG/KZZErAxAYzztG4DOxV+TRtnGqHuwwNdU//lqMYaDhnCEA+nGXn
e1q7lbSyyqCh40qC28aWvdMGu6O6GCCi7dDpIV1WTuWodfHOmBLD9UGcqj/dyr2yWq
BYboQSHmBJ7+A==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <sgff85$s6i$1@ciao.gmane.io>
Content-Language: en-GB
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
 by: dn - Sun, 29 Aug 2021 10:13 UTC

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):
>         if len(set(d)) == 1: return c, d

Curiosity:
why not add dies as a parameter of roll_die()?

Efficiency:
- wonder how max( d ) == min( d ) compares for speed with the set() type
constructor?
- alternately len( d ) < 2?
- or len( d ) - 1 coerced to a boolean by the if?
- how much more efficient is any of this (clever thinking!) than the
OP's basic, simpler, and thus more readable, form?

English language 'treachery':
- one die
- multiple dice
(probably not followed in US-English (can't recall), particularly on
computers running the Hollywood Operating System).

Continuous Education:
Thanks for the reminder that enumerate() can be seeded with a "start" value!
--
Regards,
=dn

Re: on writing a while loop for rolling two dice

<mailman.495.1630232676.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19205&group=comp.lang.python#19205

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sun, 29 Aug 2021 20:24:23 +1000
Lines: 16
Message-ID: <mailman.495.1630232676.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de wct1CuY6B8d1NWkAiMmjLQbZvRWXtMHTN+m/O4Pc4a1Q==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=po8egKmt;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'sun,': 0.07; 'aug': 0.09;
'comparison': 0.09; 'set,': 0.09; 'subject:two': 0.09;
'afterwards': 0.16; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'length.': 0.16; 'notable':
0.16; 'subject:loop': 0.16; 'subject:while': 0.16;
'subject:writing': 0.16; 'wrote:': 0.16; 'to:addr:python-list':
0.23; 'done': 0.28; 'python-list': 0.32; 'to:name:python': 0.32;
'message-id:@mail.gmail.com': 0.33; 'received:209.85.166': 0.33;
'header:In-Reply-To:1': 0.33; 'subject:for': 0.33;
'received:google.com': 0.34; 'from:addr:gmail.com': 0.35;
'neither': 0.37; 'received:209.85': 0.38; 'received:209': 0.38;
'taking': 0.40; 'speed': 0.69; '2021': 0.84; 'improvement.': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=3oPSN7UDTuju69zfYKqW4qNfAReo4v8ZJmSX0n3IQA8=;
b=po8egKmtulzSVOCVRSvoaFeA5WkSgTC82UVykOP2r8N2y3TjtC3ddMHFczYCzb121W
HfIO5rqNCqqa9+xgnpo3voJwdyWBOh/D6sK4lHQB1JruOLNDADmNFeLyt/CBYVGSI6PX
HczF7n2j6FtTVINJr+MMb6tyvDjrQ5HUuX0LhiIfOkExLZeWh/JUsd7NnCOVPRUC8abt
7aOePDwKbB5bP8lif4rlGN0OUKNKjgrXMREGBuStcKSS+Ve0hd2uYtzsTcay0koiM7M7
pNXkNTswhSZ/fkm9HqAK9QWW+COQseGr5LgOa/gHQhC0Suo/LDjxjgMBEP9df0udjl2S
F36A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=3oPSN7UDTuju69zfYKqW4qNfAReo4v8ZJmSX0n3IQA8=;
b=mWnpAmrHPYY4HCPhtwvzHvvWX+rJol8H+Q2imk0jpd1a33DfS/x2CW3uj2CnLvFwrj
w7YlPvfQro7R2PfI0rKATIgK/qYhZp0sUMqC0cCU3QfnTo50xG8FmLFOsuGh//uDG4bN
q34/hqPAP8T+7L1i67LV1atKtx72wqT8d2nVjv3Nvgnkn3tJxp1YoxuRdbjiqFA5PDg0
zT9kq6AX0X+vkhGiiMe64wghvROOEpIhw97/gQuTJONKoIHTT3VNCbG1nKBMQAgj6iNM
CWQ5i8s/UTsLXLSuaz3q1H0RU1NtV3nJ5LPIdKRjcbF0Tpze7u3rjhq0ow+e7D6V4LJd
/IYQ==
X-Gm-Message-State: AOAM5321qn5JwSd6a5GPuN38iT78ywklmtks1iaHHngy4ZA4X1QZZ3BT
He54oNlk2GRamJqcqiu21KCorr5YnCF1XiXXvAHQ1n0XRFs=
X-Google-Smtp-Source: ABdhPJxbLjwy8qEnAg8sLZrGKrb5koVWEZ3kzvM1Ekjgws8D4kdnVMMpmTIabUqYO1R6tNuA+ahoaaJd9qFcH6Ka3Q4=
X-Received: by 2002:a92:3f0b:: with SMTP id m11mr13027145ila.265.1630232674151;
Sun, 29 Aug 2021 03:24:34 -0700 (PDT)
In-Reply-To: <a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
 by: Chris Angelico - Sun, 29 Aug 2021 10:24 UTC

On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
<python-list@python.org> 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 these will make any notable improvement. The work is done
in constructing the set, and then you're taking the length. How you do
the comparison afterwards is irrelevant.

ChrisA

Re: on writing a while loop for rolling two dice

<mailman.496.1630242136.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19206&group=comp.lang.python#19206

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: __peter__@web.de (Peter Otten)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Sun, 29 Aug 2021 14:47:50 +0200
Lines: 74
Message-ID: <mailman.496.1630242136.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<sgg0gh$13lk$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de QCWJS6RkP8s4v5+S6tuItQiSUzXwl6qOtaNQKlwkDUEQ==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'parameter':
0.05; '8bit%:62': 0.09; 'explicit': 0.09; 'message-
id:@ciao.gmane.io': 0.09; 'much,': 0.09; 'ok,': 0.09;
'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'smaller': 0.09; 'subject:two': 0.09;
'though.': 0.09; "can't": 0.14; '>>>>>': 0.16; 'arguments': 0.16;
'basic,': 0.16; 'case:': 0.16; 'computers': 0.16; 'conclusion':
0.16; 'confusing': 0.16; 'dies': 0.16; 'from:addr:web.de': 0.16;
'generates': 0.16; 'initialize': 0.16; 'reason.': 0.16;
'received:116.202': 0.16; 'received:116.202.254': 0.16;
'received:116.202.254.214': 0.16; 'simpler,': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'tuple': 0.16; 'while,': 0.16; 'yield': 0.16; 'wrote:':
0.16; 'values': 0.16; 'maybe': 0.20; "i've": 0.22; 'language':
0.22; 'version': 0.22; "i'd": 0.23; 'to:addr:python-list': 0.23;
'bit': 0.28; 'module': 0.28; 'sense': 0.28; "isn't": 0.29; 'header
:User-Agent:1': 0.31; 'there': 0.31; 'think': 0.31; 'but': 0.31;
'item': 0.31; 'looked': 0.31; 'python-list': 0.32; 'header:In-
Reply-To:1': 0.33; 'subject:for': 0.33; 'running': 0.35; 'inside':
0.37; "that's": 0.37; '(or': 0.37; 'really': 0.37; 'though': 0.38;
"it's": 0.38; 'going': 0.38; 'does': 0.38; 'test': 0.40; 'skip:e
10': 0.60; 'english': 0.61; 'items': 0.61; 'check': 0.62; 'me.':
0.62; 'skip:\xc2 10': 0.62; 'numbers': 0.63; 'pay': 0.64; 'pass':
0.64; 'thus': 0.65; 'trust': 0.66; 'leading': 0.67; '[1]': 0.68;
'speed': 0.69; 'counter': 0.69; 'reminder': 0.69; 'received:116':
0.71; 'terms': 0.72; '8bit%:100': 0.75; 'die': 0.77; 'price':
0.77; 'extra': 0.84; '(first,': 0.84; 'education:': 0.84;
'system).': 0.84; 'true:': 0.84; 'duplicate': 0.93; 'hollywood':
0.93
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
Content-Language: en-US
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgg0gh$13lk$1@ciao.gmane.io>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
 by: Peter Otten - Sun, 29 Aug 2021 12:47 UTC

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 enumerate(zip(*[roll_die(faces)]*dies), 1):
>>         if len(set(d)) == 1: return c, d
>
>
> Curiosity:
> why not add dies as a parameter of roll_die()?

Dunno. Maybe because I've "always" [1] wanted a version of
random.randrange() that generates values indefinitely. It would need to
check its arguments only once, thus leading to some extra

> Efficiency:
> - wonder how max( d ) == min( d ) compares for speed with the set() type
> constructor?

I did the simplest thing, speed was not a consideration. If it is, and
dies (sorry for that) is large I'd try

first = d[0]
all(x == first for x in d) # don't mind one duplicate test

For smaller numbers of dice I'd unpack (first, *rest) inside the for
loop. But it's a trade-off, you' have to measure if/when it's better to
go through the whole tuple in C.

> - alternately len( d ) < 2?
> - or len( d ) - 1 coerced to a boolean by the if?
> - how much more efficient is any of this (clever thinking!) than the
> OP's basic, simpler, and thus more readable, form?

It really isn't efficiency, it's a (misled?) sense of aesthetics where
I've come to prefer

- for-loops over while, even when I end up with both to get the desired for

- enumerate() over an explicit counter even though there is the extra
unpack, and you still need to initialize the counter in the general case:

for i, item in enumerate([]): pass
print(f"There are {i+1} items in the list.") # Oops

> English language 'treachery':
> - one die
> - multiple dice

You might have inferred that I knew (or had looked up) the singular of
dice, so this is but a momentary lapse of reason. It hurts me more than
you, trust me. Not as much, as going on record with confusing they're
and their, but still ;)

> (probably not followed in US-English (can't recall), particularly on
> computers running the Hollywood Operating System).

I've come to the conclusion that International English is hopelessly and
inevitably broken. That's the price native speakers have to pay for
having they're (oops, I did it again!) language used as lingua franca.

> Continuous Education:
> Thanks for the reminder that enumerate() can be seeded with a "start" value!

[1] I think I've suggested reimplementing the whole module in terms of
generators -- can't find the post though.

Re: on writing a while loop for rolling two dice

<mailman.502.1630281157.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19213&group=comp.lang.python#19213

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 11:52:18 +1200
Organization: DWM
Lines: 27
Message-ID: <mailman.502.1630281157.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
<e4dd95fa-5e9d-f9d9-9185-e9a42fff772e@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de i1fqMmQTpnfLXQkTXSBR+QUpsi9NfuLfW88WvoNLwIjg==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=UCzHuggJ; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'sun,': 0.07; '=dn': 0.09;
'angelico': 0.09; 'aug': 0.09; 'comparison': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'overhead': 0.09; 'set,': 0.09; 'set.': 0.09; 'subject:two':
0.09; 'afterwards': 0.16; 'conversion': 0.16; 'length.': 0.16;
'message-id:@DancesWithMice.info': 0.16; 'notable': 0.16;
'received:51.254': 0.16; 'received:51.254.211': 0.16;
'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'subject:loop': 0.16;
'subject:while': 0.16; 'subject:writing': 0.16; 'tuple': 0.16;
'wrote:': 0.16; 'to:addr:python-list': 0.23; 'chris': 0.26;
'done': 0.28; '(and': 0.30; 'header:User-Agent:1': 0.31;
'header:Organization:1': 0.31; 'python-list': 0.32; 'header:In-
Reply-To:1': 0.33; 'subject:for': 0.33; 'neither': 0.37; 'taking':
0.40; 'skip:o 10': 0.62; 'received:userid': 0.64; 'lead': 0.67;
'plus': 0.68; 'speed': 0.69; 'little': 0.75; 'late': 0.76;
'received:51': 0.77; 'received:localhost.localdomain': 0.77;
'quickly': 0.81; 'received:localdomain': 0.81; 'returned': 0.81;
'2021': 0.84; 'improvement.': 0.84; 'received:47': 0.84; 'thus,':
0.84; 'consisting': 0.91; 'illustration': 0.91
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.6 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A autolearn=ham
autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 mail.rangi.cloud 45D0B34CF
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1630281147;
bh=VtOZZjoND0FPqfa9i1O3/5xc6e/UqJw/Qaop+6K5hwQ=;
h=Subject:To:References:From:Date:In-Reply-To:From;
b=UCzHuggJDWQB0Ey4SHHm35vQze11RJGSQy3UxIMbphbFy/K2mCou2sPYWHSA9eeN3
E9A5EKkAs+Wu4c2mTCwABRWF3meKxSUEBjab957hi8SIkOiyKVP7q0cmwaqWqZrUeI
V2VRXQwNBFeZF2celpd8u/sHD+bYDQIwrcQANoV/zPH9nj9Dnn6kjVrMxf96phOBGi
dk7HiQegdlN8OD30LQ+eZyj0tMlD/EuDZD6/QNlM3tCDRkBVwU7Kqx61rtOCjb/zEg
+7QlwmgwwNWwe09ffJsYmi4dGdiAoZ2abB7+pVYGLj7Ph92WG3ksPA6lBYl2kn9Buc
KKV0liReW78YQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
Content-Language: en-GB
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <e4dd95fa-5e9d-f9d9-9185-e9a42fff772e@DancesWithMice.info>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
 by: dn - Sun, 29 Aug 2021 23:52 UTC

On 29/08/2021 22.24, Chris Angelico wrote:
> On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> <python-list@python.org> 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 these will make any notable improvement. The work is done
> in constructing the set, and then you're taking the length. How you do
> the comparison afterwards is irrelevant.

It was far too late for either of us (certainly this little boy) to be
out-and-coding - plus an excellent illustration of why short-names are a
false-economy which can quickly (and easily) lead to "technical debt"!

The "d" is a tuple (the 'next' returned from the zip-output object)
consisting of a number of die-throw results). Thus, can toss that into
len() without (any overhead of) conversion to a set.
--
Regards,
=dn

Re: on writing a while loop for rolling two dice

<mailman.503.1630281506.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19214&group=comp.lang.python#19214

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 09:58:12 +1000
Lines: 40
Message-ID: <mailman.503.1630281506.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
<e4dd95fa-5e9d-f9d9-9185-e9a42fff772e@DancesWithMice.info>
<CAPTjJmqVpdfDpcuOCTKNbTBRiVGBe-5nmpRRf+RDLXSZvfwHFQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de CXMTI0MVD3oxEBZAUK0Ozwly8m3GKdlSHDelUvjms6bA==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=tb/FQxBx;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.006
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'tests': 0.05; 'sun,':
0.07; 'angelico': 0.09; 'aug': 0.09; 'comparison': 0.09;
'options,': 0.09; 'overhead': 0.09; 'set,': 0.09; 'set.': 0.09;
'subject:two': 0.09; 'afterwards': 0.16; 'chrisa': 0.16;
'conversion': 0.16; 'difference,': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'length.': 0.16; 'min': 0.16;
'notable': 0.16; 'scans': 0.16; 'subject:loop': 0.16;
'subject:while': 0.16; 'subject:writing': 0.16; 'tuple': 0.16;
'wrote:': 0.16; 'python': 0.16; 'calls': 0.20; 'to:addr:python-
list': 0.23; 'probably': 0.24; 'chris': 0.26; 'length': 0.27;
'done': 0.28; '(and': 0.30; 'there': 0.31; 'but': 0.31;
'difference': 0.32; 'python-list': 0.32; 'to:name:python': 0.32;
'message-id:@mail.gmail.com': 0.33; 'using': 0.33;
'received:209.85.166': 0.33; 'requires': 0.33; 'header:In-Reply-
To:1': 0.33; 'subject:for': 0.33; 'received:google.com': 0.34;
'well,': 0.35; 'from:addr:gmail.com': 0.35; 'neither': 0.37;
'two': 0.37; 'received:209.85': 0.38; 'received:209': 0.38;
'taking': 0.40; 'skip:o 10': 0.62; 'skip:b 10': 0.62;
'everything': 0.64; 'lead': 0.67; 'choice': 0.68; 'plus': 0.68;
'speed': 0.69; 'generator': 0.69; 'performance': 0.74; 'little':
0.75; 'late': 0.76; 'quickly': 0.81; 'returned': 0.81; '2021':
0.84; 'improvement.': 0.84; 'thus,': 0.84; 'consisting': 0.91;
'illustration': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=wJUYq/6D0CDXszNFp91sKw5HBj0KGjDJ2zSu3PhW+84=;
b=tb/FQxBx1LBRI7LIhpoeUpzhPBr/S3TtHRrYrdGRM2KUNf86IAZSflU9fuu0RhZqyo
efNn/be1q+0jB8dXrtAyxTCBtnsVzdh21bZggJ0gh+/n04Ix332dTAaX3eSmzO06S8Sm
soGvi88WfFvg4R+yW/tqI3qRu+XSA/MkwGqOwjN138CYLtTaZ0zl67Cavq7HoEtMBqsW
wyDWus/hkb0nOoxVZqTkv/zWrXVO2puKicv2i27iPSDRml0V7EEUyKXGWDdE9s4uuWf8
3dq6ypsZi76g54YOqJOf20lf7oP+mvoNUUa5gODerRp8VDK91APvIegXdZV4TL0f+VCG
evLQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=wJUYq/6D0CDXszNFp91sKw5HBj0KGjDJ2zSu3PhW+84=;
b=h4GhnhASUfoNSLCHG+5v+hRrFUUf7xb6O8EYAF1oi+cFTXYEHtoX4Xl3EdFe13Xm46
nYaD6QJmUNrlN6Oqo3QxL1r4saZpVoqFZiRP6wqX2pV61DcOd5o1EQf7myIkLvSflOiJ
PqF22wIZjZWnQwAlLWzcnEQqAU+gOdg0glezSDgb3zrqoGXXrB0LJt6CFTg9oFpMKNOk
QvvjSQqklnJKQPrnueysFwGkiMGejAWts3Astu9qMPzX3IucIgrbJoOY4ETBqf+ma7y/
yNDjkuDrWcQYx1x9yQ+LpCab9vcR7gyB114X2h7KDOsAi6oKeaeHa/txWJxRsUsOMhKC
tBYg==
X-Gm-Message-State: AOAM5326WYJJ5RGDn8zKTgYg4llQkddOwX9aEvuVXFWnDVK8txxfgA6Z
k8Ccl3GTC0zW8gKVv1ORWqj4MfsBx7/5dZd1AqC8n9Q551U=
X-Google-Smtp-Source: ABdhPJzNXS84sYP+8Y0jSDsOB/tA/vIxis43Ycruew3URS1zPz5eFMKb3e8LNgW66fkqzIdhd4fTlRLSKb6LAKDHGsA=
X-Received: by 2002:a05:6602:3404:: with SMTP id
n4mr16064504ioz.45.1630281503700;
Sun, 29 Aug 2021 16:58:23 -0700 (PDT)
In-Reply-To: <e4dd95fa-5e9d-f9d9-9185-e9a42fff772e@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmqVpdfDpcuOCTKNbTBRiVGBe-5nmpRRf+RDLXSZvfwHFQ@mail.gmail.com>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<CAPTjJmrPK-wyjxWsMt4Ej1gmSkxDamrS0LpBs64++GBbhkbEdA@mail.gmail.com>
<e4dd95fa-5e9d-f9d9-9185-e9a42fff772e@DancesWithMice.info>
 by: Chris Angelico - Sun, 29 Aug 2021 23:58 UTC

On Mon, Aug 30, 2021 at 9:53 AM dn via Python-list
<python-list@python.org> wrote:
>
> On 29/08/2021 22.24, Chris Angelico wrote:
> > On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> > <python-list@python.org> 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 these will make any notable improvement. The work is done
> > in constructing the set, and then you're taking the length. How you do
> > the comparison afterwards is irrelevant.
>
> It was far too late for either of us (certainly this little boy) to be
> out-and-coding - plus an excellent illustration of why short-names are a
> false-economy which can quickly (and easily) lead to "technical debt"!
>
>
> The "d" is a tuple (the 'next' returned from the zip-output object)
> consisting of a number of die-throw results). Thus, can toss that into
> len() without (any overhead of) conversion to a set.

Oh. Well, taking the length of the tuple is fast... but useless. The
point was to find out if everything in it was unique :)

Conversion to set tests this because the length of the set is the
number of unique elements; checking max and min works because two
scans will tell you if they're all the same; using all with a
generator stops early if you find a difference, but requires
back-and-forth calls into Python code; there are various options, and
the choice probably won't make a material performance difference
anyway :)

ChrisA

Re: on writing a while loop for rolling two dice

<mailman.505.1630297056.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19217&group=comp.lang.python#19217

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonList@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 16:17:12 +1200
Organization: DWM
Lines: 251
Message-ID: <mailman.505.1630297056.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<sgg0gh$13lk$1@ciao.gmane.io>
<6fcf22af-fbf8-7a7b-4123-16765d431758@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 9fDqboFp0nlFgVhY1aGbSwJgeWdQnDPQsE8iQa+ufmhQ==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=GiEzmxH+; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'project,': 0.03; 'def':
0.04; 'parameter': 0.05; "python's": 0.05; '(to': 0.07; 'coder':
0.07; 'exercises': 0.07; 'linux': 0.07; 'loop': 0.07; 'loops.':
0.07; '=dn': 0.09; 'al.': 0.09; 'comparison': 0.09; 'describe':
0.09; 'enabling': 0.09; 'explicit': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'humor': 0.09; 'much,': 0.09; 'ok,': 0.09; 'simplicity':
0.09; 'situations': 0.09; 'smaller': 0.09; 'subject:two': 0.09;
'though.': 0.09; 'coding': 0.10; "can't": 0.14; '(both': 0.16;
"(i'm": 0.16; '(it': 0.16; '>>>>>>': 0.16; 'approach.': 0.16;
'apropos': 0.16; 'arguments': 0.16; 'basic,': 0.16; 'be)': 0.16;
'case:': 0.16; 'collection.': 0.16; 'computers': 0.16;
'conclusion': 0.16; 'confusing': 0.16; 'confusion': 0.16;
'controlling': 0.16; 'cope': 0.16; 'dies': 0.16; 'docs?': 0.16;
'examine': 0.16; 'expectation': 0.16; 'finger': 0.16; 'generates':
0.16; 'grounds': 0.16; 'harness': 0.16; 'help:': 0.16;
'impossible': 0.16; 'initialize': 0.16; 'logic?': 0.16; 'loops':
0.16; 'loops,': 0.16; 'maps,': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'proportion': 0.16; 'python")':
0.16; 'readability': 0.16; 'real-world,': 0.16; 'reason.': 0.16;
'recall': 0.16; 'received:51.254': 0.16; 'received:51.254.211':
0.16; 'received:51.254.211.219': 0.16; 'received:cloud': 0.16;
'received:rangi.cloud': 0.16; 'simpler,': 0.16; 'simulation':
0.16; 'stats': 0.16; 'subject:loop': 0.16; 'subject:while': 0.16;
'subject:writing': 0.16; 'tends': 0.16; 'tuple': 0.16; 'while,':
0.16; 'whilst': 0.16; 'word,': 0.16; 'yield': 0.16; 'wrote:':
0.16; 'says': 0.16; 'values': 0.16; 'python': 0.16; 'larger':
0.18; 'maybe': 0.20; 'option': 0.21; "i've": 0.22; 'language':
0.22; 'version': 0.22; "i'd": 0.23; 'to:addr:python-list': 0.23;
'discussion': 0.24; 'feedback': 0.24; 'lines': 0.24; 'views':
0.24; 'run': 0.24; 'code': 0.24; 'probably': 0.24; "you'll": 0.75;
'business': 0.75; 'features': 0.76; 'die': 0.77; 'languages,':
0.77; 'received:51': 0.77; 'received:localhost.localdomain': 0.77;
'well!': 0.77; 'price': 0.77; 'relationship': 0.78; 'discovered':
0.81; '8bit%:67': 0.81; 'received:localdomain': 0.81; 'spent':
0.81; 'glad': 0.82; 'extra': 0.84; "'the": 0.84; '(first,': 0.84;
'btw': 0.84; 'cycle': 0.84; 'education:': 0.84; 'job,': 0.84;
'mine.': 0.84; 'powerful,': 0.84; 'project!': 0.84; 'quotation':
0.84; 'received:47': 0.84; 'reflection': 0.84; 'reversed': 0.84;
'suffered,': 0.84; 'system).': 0.84; 'thus,': 0.84; 'true:': 0.84;
'8bit%:77': 0.91; 'annually': 0.91; 'heads': 0.91; 'illustration':
0.91; 'lose': 0.91; 'nations': 0.91; 'of:': 0.91; 'placing': 0.91;
'that:': 0.91; "world's": 0.91; 'duplicate': 0.93; 'former': 0.93;
'hollywood': 0.93; 'sale': 0.97
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.6 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A autolearn=ham
autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 mail.rangi.cloud 331854E13
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1630297052;
bh=R6uoJP3TBC+cDVusI1RiIzSSp5eMVgnRVwOP54DBYhM=;
h=Subject:To:References:From:Date:In-Reply-To:From;
b=GiEzmxH+FAqDUxsWBT7iwA+RItQh/RqkMXCD20MmJv3kaQDKaytCQCMke1Zz4OwqM
BWGk5yOs0MttbCs04tOCS6anCgwwXyKQOPw+4O7KapM7I4bv4D66tpjwyo+VNELCAh
jZ/wUsjlWNsf1CsOw1Ji22NmTL3VqUMqsnUfoP+E3nqvd+p6C/hCezwkxcX13k8U52
IcsYpqsSgWdCshRpyMjSDBoX9Vo4D7DEDEOcyW7g2LgITiG00uM12QapnqIggGIUAc
wI1oFNxBq9fF5jMttfnv+4B+m8huaqmSyOfskbGFMJMCTW+a1/KTJkuaa2tyJ9qQRn
iE+DIMwO/Rvmg==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <sgg0gh$13lk$1@ciao.gmane.io>
Content-Language: en-GB
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <6fcf22af-fbf8-7a7b-4123-16765d431758@DancesWithMice.info>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<sgg0gh$13lk$1@ciao.gmane.io>
 by: dn - Mon, 30 Aug 2021 04:17 UTC

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.randrange(1, 1 + faces)
>>>
>>>>>> def hmt(faces, dies):
>>>      for c, d in enumerate(zip(*[roll_die(faces)]*dies), 1):
>>>          if len(set(d)) == 1: return c, d
>>
>>
>> Curiosity:
>> why not add dies as a parameter of roll_die()?
>
> Dunno. Maybe because I've "always" [1] wanted a version of
> random.randrange() that generates values indefinitely. It would need to
> check its arguments only once, thus leading to some extra

Each code-unit should do one job, and do it well!
SRP...

>> Efficiency:
>> - wonder how max( d ) == min( d ) compares for speed with the set() type
>> constructor?
>
> I did the simplest thing, speed was not a consideration. If it is, and
> dies (sorry for that) is large I'd try
>
> first = d[0]
> all(x == first for x in d)  # don't mind one duplicate test
>
> For smaller numbers of dice I'd unpack (first, *rest) inside the for
> loop. But it's a trade-off, you' have to measure if/when it's better to
> go through the whole tuple in C.

For larger numbers of dice, and presuming a preference for an
inner-function which rolls only a single die per call; would it be more
efficient to test each individual die's value against the first,
immediately after its (individual) roll/evaluation (rinse-and-repeat for
each die thereafter)? This, on the grounds that the first mis-match
obviates the need to examine (or even roll), any other die/dice in the
collection.

OTOH the simulation of rolling n-number of dice, as would happen in the
real-world, would be broken by making the computer's algorithm more
efficient (rolling until the first non-equal value is 'found'). Does
that mean the realism of the model dies?
(sorry - no, I'm not sorry - you deserved that!)

Does one "roll" a die, or "shake the dice"???

We don't know the OP's requirements wrt to execution-efficiency.
However, as you (also) probably suffered, such exercises regularly
feature in stats and probability courses. Sometimes 'the numbers' are
quite large in order to better-illustrate ("smooth") distribution
characteristics, etc.

I have a love?hate relationship with questions of Python and
'efficiency'. Today, discovered that using a cut-down Linux version (on
AWS) was actually slower than using a full-fat distribution - upon
analysis, my friendly 'expert' was able to point the finger at the way
the two distros compiled/prepared/distribute the(ir) Python Interpreter.
(I'm glad he thought such investigation 'fun'!) All of which further
complicates the business of design, given we already know of situations
where approach-a will run faster than approach-b, on your machine; yet
the comparison may be reversed on mine.

This discussion forms a sub-set of that: when to use the built-in
functions (implemented in C) because they are (claimed to be) more
efficient than another approach - and, when one approach using a
built-in function might be faster than another 'built-in'/C-coded approach.

("small things amuse small minds" - mind how you describe my mind!)

"Bottom line": I prefer to think of Python's "efficiency" as reflected
in the amount of my time that is needed, in order to complete a project!

>> - alternately len( d ) < 2?
>> - or len( d ) - 1 coerced to a boolean by the if?
>> - how much more efficient is any of this (clever thinking!) than the
>> OP's basic, simpler, and thus more readable, form?
>
> It really isn't efficiency, it's a (misled?) sense of aesthetics where
> I've come to prefer
>
> - for-loops over while, even when I end up with both to get the desired for
>
> - enumerate() over an explicit counter even though there is the extra
> unpack, and you still need to initialize the counter in the general case:
>
> for i, item in enumerate([]): pass
> print(f"There are {i+1} items in the list.")  # Oops

Next thing you'll be using for-else...
[insane giggling]

It's interesting how we arrive at these views (as a trainer I spend a
lot of time trying to detect how learners build their mental maps, or
"models", of each topic).

I've always had a clear 'formula'/rule/hobgoblin: if the number of loops
can be predicted, use 'for', otherwise use 'while'.

Of course, Python alters that view because it offers a for-each, which
means that I don't need to know the number of loops, only that the loop
will cycle through each item in the iterable.

It used to be a far simpler world!

That said, I really miss the option of while controlling the loop with a
pre-condition AND having a repeat...until controlling the loop with a
post-condition - the former enabling >=0 loops; the latter, requiring at
least one!

Using enumerate() may be a matter of aesthetics (English-English
spelling!). However, it is a basic Python idiom. It is as much a tool in
our coding as a fork/spoon/chop-sticks/fingers are to someone eating.
(yes, I'm feeling hungry).

At times I feel a 'siren call' to use some of the powerful, let's call
them "one-liner" tools, because it is 'fun' to bend my mind around the
challenge. However, most such code tends to lose readability in some
sort of inverse proportion to its power - it leaves the clarity and
simplicity of Python-space and heads towards APL, Lisp, et al.

The 'problem' is that as a coder increases his/her knowledge (learns to
harness 'the force'), the code-structures which count as one "chunk" of
thought, expand. For example, it can be difficult to see (remember) that
although comprehensions may have become a single 'unit' of thought to a
skilled practitioner; for others they are (still) opaque, and
'mountains' to climb.

Thus, the 'balance' between 'power' and readability; and between using
techniques which demand Python-expertise and thus carry an expectation
that less-capable/-experienced programmers will 'improve their game' (to
be able to contribute to 'this' project, or future re-use/maintenance).
(see also "Zen of Python")

The 'level' then becomes a convention - just as much as 'do we adhere to
PEP-008 naming' (etc). The important point is not what the convention
is, but that the team has arrived at a pragmatic agreement, eg will we
use comprehensions or explicit loops. Your team might say "of course",
whereas mine says "can't cope with that"...

BTW you already know this, but I'm not writing only to you!
(don't fret, you're still 'special'...)

>> English language 'treachery':
>> - one die
>> - multiple dice
>
> You might have inferred that I knew (or had looked up) the singular of
> dice, so this is but a momentary lapse of reason. It hurts me more than
> you, trust me. Not as much, as going on record with confusing they're
> and their, but still ;)

Reason? Logic? Consistency?
The English language.
Surely, you jest...

Having learned/lived many languages, struggling-mightily with some,
feeling comfortable with others; I am enormously grateful (greatly
grateful?) that English was one of my home-languages, and that I didn't
have to "learn" it!

I do enjoy 'playing' with it though, and as pointed-out annually
(?semesterly), making students groan in response to my
weak/pathetic/Dad-joke/seven-year-old's humor (in live-lectures) at
least gives feedback that they are 'there' and paying some attention.
(alternately, it's Pavlovian-conditioning - BTW: yes, I'm still hungry...)

Please consider the die/dice as 'educational', and a reflection of my
confusion of comprehension when trying to infer meaning whilst reading
the code-example - rather than arrogance or placing undue demand on you.

>> (probably not followed in US-English (can't recall), particularly on
>> computers running the Hollywood Operating System).
>
> I've come to the conclusion that International English is hopelessly and
> inevitably broken. That's the price native speakers have to pay for
> having they're (oops, I did it again!) language used as lingua franca.

If English really set-out to be the world's lingua-franca, why didn't it
come up with its own, a particularly (and peculiarly) English word, for
the concept???

I've spent quite some time looking into the idea of 'International
English' - to attempt to find 'an English' to employ in our course
materials used world-wide. Even 'native speakers' can't agree on what is
'English'! When the question is widened to include the broader, majority
of the world; the concept of a 'core' of English becomes impossible to
define or encapsulate...


Click here to read the complete article
RE: on writing a while loop for rolling two dice

<mailman.506.1630329121.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19219&group=comp.lang.python#19219

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: David.Raymond@tomtom.com (David Raymond)
Newsgroups: comp.lang.python
Subject: RE: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 13:11:53 +0000
Lines: 7
Message-ID: <mailman.506.1630329121.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
X-Trace: news.uni-berlin.de 56YwBROyiPKeF7In+2w4rQW4b/pDYoXq4G4gtvBxEduw==
Return-Path: <David.Raymond@tomtom.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=tomtom.com header.i=@tomtom.com header.b=jks0MDHU;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.025
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'def': 0.04; 'subject:two':
0.09; 'received:40.107.21': 0.16; 'subject:loop': 0.16;
'subject:while': 0.16; 'subject:writing': 0.16; 'option': 0.21;
'to:addr:python-list': 0.23; 'to:name:python-list@python.org':
0.28; 'answers': 0.32; 'using': 0.33; 'header:In-Reply-To:1':
0.33; 'subject:for': 0.33; 'skip:h 10': 0.61; 'our': 0.63; 'seen':
0.65
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=jGx9hs/lQz+CEm7Spl0lLytud528z5FMXS/Hp72MU3R2PV9Q7AtOs3Cm5cKJ3v9yqem5tkuoHnWqXInzUY6CnYA/rsz1jppsb+1bDtFndgWvsOCP1lEym1qiGhM6bUii0psXyPZ9AdFDPJ/Lu2ddj217JFGFznHwiXVDREaLFsQomv43/ZaeHA+3R9m5y1xFJx4YyzrWe47dVxyhA64AZHJD9HVOb/hEKjGmICjygubCNuPyGTROyE0U7ryuqu+B7KccaTVm34eagJESSYd5ChxmORauYzXYhuvcrMj9iqcimbOekpGVll9eJ921KpXxkBFgLG4eZA6PGmAqc5Zn0A==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version;
bh=rpf6wOTyFub7bCRiP2iutr9LrtwohDbseLeYJWpwKho=;
b=UwbnKdmjiHQ9bWofRFOc2FY/CAjDP0xVnq+ua+bAu5flE4Ihd8gItFhUOMpUcKhcHwGbcI52mK+nkbW/iesqxMq9IWuI8nAWYDsUDLy9af3Y6P4XITaGwQZ6Fg4jeDA8WrWVDTMXi3e02putXTdmZ3+wJ2nmYapDCgZxpLbOX/X5SKe+wx6iRinM8+XAqDUoU6NbYubMze29TXt3aoSfOsPrJjkBs8T+USfLKdYqPIqkdvVCKRHeMJqC7+5Xq0DhuYga69AWHcMCuMOjTNLoIIVUX1DkJBzqdzjYnzLtJ2qcSnkgSCltY9/gf1GULmBcpDjJObcVzOSrTBkBW7/A7g==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=tomtom.com; dmarc=pass action=none header.from=tomtom.com;
dkim=pass header.d=tomtom.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tomtom.com;
s=selector2;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=rpf6wOTyFub7bCRiP2iutr9LrtwohDbseLeYJWpwKho=;
b=jks0MDHUZYMm/+GIOzobXCo6LdDWelAMS+mqVOERgGJbSlnn8pH9kDX26xkYsydApAxnxc7Q9yj2hyX4kTcdgkx/EzuE0MMdWkoFn8vGVOFYLd/xSS0dcTP7vf/oi41G8kkFnPlzYy5bzIPm3Tjh+YKO0KEx9MVpLd7jT9XIX/c=
Thread-Topic: on writing a while loop for rolling two dice
Thread-Index: AQHXnFTkvYnbL3Y0DEiXnX57/qxcUKuMByuQ
In-Reply-To: <86r1edlqxw.fsf@jevedi.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: python.org; dkim=none (message not signed)
header.d=none;python.org; dmarc=none action=none header.from=tomtom.com;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: a3e159a8-c973-4ed9-ffc9-08d96bb7bc7d
x-ms-traffictypediagnostic: AM4PR0701MB2276:
x-microsoft-antispam-prvs: <AM4PR0701MB2276F6FA158C37095123645D87CB9@AM4PR0701MB2276.eurprd07.prod.outlook.com>
x-ms-oob-tlc-oobclassifiers: OLM:2733;
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: xCzqT+4+RPKd5Bri+4JoGX1j7bcfoYQxNpozKfHrOwljR56ro8qSxUjI9DO80+uZfdKcTi6wG5P6taR20IjLxQxd20RRJ7xoBf6/ekwyKbPziaSznPdKH1WuNJQbE7st6zLmrqmUZefzpoVJY96/0cTnMfCkQCQ2qDJKMcwUUsd6IaoTn9w+3RRwcj3W0uUhlfPQ0FUXl8Mrrm+xfDPnOOJzmWTCGXZ3mO4jFUY4f2216wU55pOuOGotj9BZlrvDlIQskJhqXuB3w5X7A2Gu4fQyy8atBWVLxpu0CuHAIDLtYX7dXEM0fwqzMqfpjNqGdu0rLbI+Gewq5pcQ+CUf5BcwJlpv+WSea5S5QEug1SzXS8xfmQbi+Z7gU8p4stF0PvwnU/azkh/mv2PPSlBmlXLxtn874V0GESUKjskLvCOWUBXGVVKYsfQ238gpU4AihSGlPd+mkGr1JlWYL8P2vWpqinmC3yiZyD+UcvRp1ovsZRZNJy7jEsFDK0BQ4BOaJooObd0F+0bRf2vmHSimGkKLjO6ilNB/Nh6zL3UZmZtTqyCIIpGhxIZIXirsRuKqLLAniBgAuNB0fFWQSjyI6NovAp4OW3BQI+74zxgVkLJNDRXOeoy7pZUT7s0VUU/w5l8X18Pz+RAGYkj8SfXtHuBXnAeSwyNZTMsashlz8LJvIOsF/B9uLt9mLiX1M1H5kUC4tMVwiq4MRz+pCccTQw==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:AM0PR07MB5700.eurprd07.prod.outlook.com; PTR:; CAT:NONE;
SFS:(4636009)(366004)(136003)(346002)(376002)(396003)(39850400004)(55016002)(66556008)(66946007)(66446008)(66476007)(76116006)(122000001)(4744005)(38100700002)(52536014)(38070700005)(64756008)(71200400001)(186003)(5660300002)(316002)(33656002)(86362001)(6506007)(8936002)(26005)(2906002)(7696005)(8676002)(6916009)(9686003)(478600001);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: qsSgWjhLOEloxj7c7fxiN5Q+nSNmsT8hNEveCGSmdTFzk
bHBRt9wsDciqv4asG6DWDsmLb0uqH8S2LGO3JZSfGLyIn
5liPRf4flf6cNI/TlFdyqO5gz9b19x98dkHhzt4ddptVw
OWbjGQJrXqRtGVIS8IuOKrQvINzOkn2ClKEcQBoSjB6lZ
mVmv7j9i4n54LbiFV7eG9b2jaN6/PIpDYUE8GIFV3lHJ6
4w0ZrP/1MRQ5aknS6lF3sn9dWvZAa6a7HdwfLQC+e7nEa
pixU0MuLl+Jc2J5/txF04djUdME5cH+b1G0TKiUYRlST9
1uS6jJiHgVJekv5JO3E/BE/2tohJb2rUma2NMWotiZazP
l6xgu2QP9TxxyRwM5z3i94Fr9Rex0dc5YBcwfehvL7w/X
cL4ecyiKqCPLcTy3rdaRjqD+tge0Dv+UMd71m8xieX8IB
HFBvQYsKoeBmOCG2/1R0UQWkgAVV9Vs8QuGimfWXciT2n
d/ZinnChfnr4GcyvJKRbuqYix/7uKIdDCBM4huvmPES3A
nRcXJjnH3cvxoLR1zK46VLvV9/lCygwFGUYSDfd/GczZD
PIPlCDgO/u3gzJs5bZ/BoY84xZ0Ofly0wOmeJmPtB8UJA
/u+HW/zUqqUSMkpvYi1wJ/La+3niLeXW2zLmQ8XHg1asV
aw1OagZBk4kBB8bEGb4sO0+hK6DVRpVS2dA7xJZ4d33pT
SBwU+0Y1Fjb9plHePxYkbetjC9/P4e3donq1DOre89gVE
mhydksMcDB/i5EcLml8go1E9jYc8IIkf2a5O9JOo6aq6P
pgL0WyXK8BbvZ4vNLWPJTjlztaR+6iqquM80E7de/qeKi
IsDEDfpbBg7phsGjcLtkUJ5fcZQYlFjRP7ATkddNRaYl+
qZXc1Gf+ezRwNoOy9B2P8UktTDBEtBa43NCkeISvDTE0q
9oWJOHZqRE4T+i33H68O/C9vmHcoyO4UUNLU5Zm8GN90t
FihC4jisy35OSY3h75ZH6jHnFCyD5H9heX8enWa891e0j
p2Hyc92pKuDIGMUd+nM2fokElth0aQEAM0SIvRhKKOg36
xgdqPt3XqtUAxg7AT9TVE/JcKOgycbjh/PXky2HT60t2H
vOrgCgPmTAqwd2TNboo0o0hCDMw6rzpTtrucg/4xuKJPT
We8Wdqczc6S6MEKogEF5GtSzim5vxG1ixCGmKtW+ecxna
pJ3EBow80m1FU4Ekj/RCT2RRA9F/n9NV0do62g3+JTY7W
N+zeAPXJeLde0ZenV1ZiInd7fRUiLhOZraYi9Yq43F3f9
0iGgfLXq6ZgNadMFEyyR7YOmcTu5y4VDT1FIfPd
x-ms-exchange-transport-forked: True
X-OriginatorOrg: tomtom.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: AM0PR07MB5700.eurprd07.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: a3e159a8-c973-4ed9-ffc9-08d96bb7bc7d
X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Aug 2021 13:11:53.4277 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 374f8026-7b54-4a3a-b87d-328fa26ec10d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: BUxEuUYCy4U1dCa0Weta6xwjD4nDd387ehlUNdbWR1xKICIhKXEXyfvzGM+KisnKsf5QCbgmZdagSkTNQtmmHTjvd69LgOXkAD4FwIB8FCo=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR0701MB2276
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
 by: David Raymond - Mon, 30 Aug 2021 13:11 UTC

> def how_many_times():
> x, y = 0, 1
> c = 0
> while x != y:
> c = c + 1
> x, y = roll()
> return c, (x, y)
Since I haven't seen it used in answers yet, here's another option using our new walrus operator
def how_many_times():
roll_count = 1
while (rolls := roll())[0] != rolls[1]:
roll_count += 1
return (roll_count, rolls)

Re: on writing a while loop for rolling two dice

<mailman.507.1630331441.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19220&group=comp.lang.python#19220

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 23:50:27 +1000
Lines: 30
Message-ID: <mailman.507.1630331441.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
<CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 7hvqxqJ6c9l++5lyp35GMwG+xr81cFTrTvb3W0HZQtzQ==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=PgMc2ozl;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.041
X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'def': 0.04; 'aug': 0.09;
'subject:two': 0.09; 'chrisa': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'subject:loop': 0.16;
'subject:while': 0.16; 'subject:writing': 0.16; 'wrote:': 0.16;
'uses': 0.19; 'option': 0.21; 'version': 0.22; 'to:addr:python-
list': 0.23; 'creating': 0.27; 'to:name:python-list@python.org':
0.28; "doesn't": 0.32; 'answers': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'using': 0.33; 'received:209.85.166':
0.33; 'header:In-Reply-To:1': 0.33; 'subject:for': 0.33;
'received:google.com': 0.34; "we're": 0.35; 'from:addr:gmail.com':
0.35; 'received:209.85': 0.38; 'received:209': 0.38; 'use': 0.38;
'completely': 0.60; 'skip:h 10': 0.61; 'our': 0.63; 'seen': 0.65;
'skip:e 20': 0.70; 'solutions': 0.71; 'features': 0.76; '2021':
0.84; 'points': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=I/gNR7g+0xqnWzZ8EglrCfBs5fnPyLM35UVrFKuZars=;
b=PgMc2ozlFqo1v+46vdzBxlqCWASQqAIl/NrOexpv+UTX/ZqcrSd/HeKKDR0oiyDgmK
OtkE+GFcoJtSDTFh4nGEVcfn+ecNRcmsegjdNfzOQzocDn+Xqu5yRFpqUOZivMf5sM5V
v4rehuUKR7PGClc7oSRocT+ioleVUcNcYlHjDJNDTlogoaclLjNw/4GHYY9Ly8HDp+83
fUrYukHiAKvm/xcTbgaTj0zCS1Ouim/QpGq63Lfe13Ck6l3rC09a5eUTMJkZTAr5eBjX
NqL+3GjS/bbRNA6PQD3v5IdtBfee2S9TwC1HvspbUS0BqW5DuNhh76rl7aeLElQeuvI9
2ajA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=I/gNR7g+0xqnWzZ8EglrCfBs5fnPyLM35UVrFKuZars=;
b=b+wKy8yarTyZssQ1Vpttae2SGaTwniZ6NeuA1jCgIggJ+gVqE+HmdSmuKgWowIOX67
hu/cGJuVgs2s7fb294JJdzUtw7WQGagl668TdLrd/Bk/WNLKEMvB/YYTppIG8fUkMP8G
eH/BL0Yg5xoeLk6sX2q6Dee738Rm0QclUOUu1GShcXBphRNOYtdSXzfRMsyDn7RtxCDE
RuX+PGpcu9mhCS9nbpWLvqcXeyBJI8rU1Yu05JRJFPNbDNyDLJggzPxcewBvPsvoZWMC
ikCg0xROWuFSaXBRoba/BW/pSGc3cBEkCE6gBVCL5E+QUdjLGeqgJXcqeckHtbZB/1ao
BwRA==
X-Gm-Message-State: AOAM531o7xPDmNsSDuvuhfYdbfINebGpJ0tkDF2u9YSsuNxEXM/xj8qd
ylIiM6aHWwKBewXtG0ZE9NCBcfgBV6a1K1PdEtKlkshqVkU=
X-Google-Smtp-Source: ABdhPJwXmpbc6H+ayoqaGTLtqzwIpszatznruPrtAWipRGONitN6fZDSiXfJhzi+aeMrpcoFY+3TWAvFcpQnO4HMtCE=
X-Received: by 2002:a92:da87:: with SMTP id u7mr17087057iln.297.1630331438796;
Mon, 30 Aug 2021 06:50:38 -0700 (PDT)
In-Reply-To: <AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
 by: Chris Angelico - Mon, 30 Aug 2021 13:50 UTC

On Mon, Aug 30, 2021 at 11:13 PM David Raymond <David.Raymond@tomtom.com> wrote:
>
> > def how_many_times():
> > x, y = 0, 1
> > c = 0
> > while x != y:
> > c = c + 1
> > x, y = roll()
> > return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our new walrus operator
>
> def how_many_times():
> roll_count = 1
> while (rolls := roll())[0] != rolls[1]:
> roll_count += 1
> return (roll_count, rolls)
>

Since we're creating solutions that use features in completely
unnecessary ways, here's a version that uses collections.Counter:

def how_many_times():
return next((count, rolls) for count, rolls in
enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)

Do I get bonus points for it being a one-liner that doesn't fit in
eighty characters?

ChrisA

Re: on writing a while loop for rolling two dice

<mailman.508.1630333618.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19221&group=comp.lang.python#19221

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: __peter__@web.de (Peter Otten)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 16:20:16 +0200
Lines: 16
Message-ID: <mailman.508.1630333618.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
<CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
<sgipr7$946$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de Bb2BaIpv23S7Gx74SAgdxwKTtxxds+GvqdQYuKJpNv6g==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'angelico':
0.09; 'message-id:@ciao.gmane.io': 0.09; 'received:ciao.gmane.io':
0.09; 'received:gmane.io': 0.09; 'received:list': 0.09;
'subject:two': 0.09; 'from:addr:web.de': 0.16; 'received:116.202':
0.16; 'received:116.202.254': 0.16; 'received:116.202.254.214':
0.16; 'subject:loop': 0.16; 'subject:while': 0.16;
'subject:writing': 0.16; 'wrote:': 0.16; 'version': 0.22; 'to:addr
:python-list': 0.23; 'run': 0.24; 'chris': 0.26; 'header:User-
Agent:1': 0.31; 'but': 0.31; "doesn't": 0.32; 'header:In-Reply-
To:1': 0.33; 'subject:for': 0.33; "that's": 0.37; 'skip:h 10':
0.61; 'skip:e 20': 0.70; 'received:116': 0.71; "you'll": 0.75;
'points': 0.84
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
Content-Language: en-US
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgipr7$946$1@ciao.gmane.io>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
<CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
 by: Peter Otten - Mon, 30 Aug 2021 14:20 UTC

On 30/08/2021 15:50, Chris Angelico wrote:

> def how_many_times():
> return next((count, rolls) for count, rolls in
> enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)

That's certainly the most Counter-intuitive version so far;)

> Do I get bonus points for it being a one-liner that doesn't fit in
> eighty characters?

Nah, but you'll get an honorable mention when you run it through
pycodestyle without line break...

Re: on writing a while loop for rolling two dice

<mailman.509.1630333919.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19222&group=comp.lang.python#19222

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rosuav@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Tue, 31 Aug 2021 00:31:45 +1000
Lines: 24
Message-ID: <mailman.509.1630333919.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
<CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
<sgipr7$946$1@ciao.gmane.io>
<CAPTjJmqsmdTZe6QJF3y6Q72hvV5OXiD7CkTwj_pxArr3PQ5gTA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de lhjYEWh7/2lRceNUlDx4/A7KaL2sh1D2d/vyXMbgd4xw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=TmkkD5lS;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.007
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'def': 0.04; '31,': 0.05;
'angelico': 0.09; 'aug': 0.09; 'subject:two': 0.09; 'chrisa':
0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'wrote:': 0.16; 'tue,': 0.18; 'version': 0.22; 'to:addr
:python-list': 0.23; 'run': 0.24; 'chris': 0.26; 'there': 0.31;
'but': 0.31; "doesn't": 0.32; 'to:name:python': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'received:209.85.166': 0.33; 'header
:In-Reply-To:1': 0.33; 'subject:for': 0.33; 'received:google.com':
0.34; 'from:addr:gmail.com': 0.35; "that's": 0.37;
'received:209.85': 0.38; 'received:209': 0.38; 'use': 0.38;
'skip:h 10': 0.61; 'skip:e 20': 0.70; "you'll": 0.75; '2021':
0.84; 'points': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=Vp/WxRNJpMQfioH05N4egSJpNowmnUxigvgfF/35crI=;
b=TmkkD5lSpbMRa+mpXmQcc+cnKnvZ+WFMtV56AD/ptcQThYZw2Aio31zKCpQ4x2k87T
xGUDCiTrwELJksVOHwHixw1fphoXo7kZqPGpbphbwjZsJoN/pqNvMebq0MAJKuj3DnNl
TDfAllPaJHoV+KpcjnCrlLIOor1HB0YyzQPJHvpqzSPfgSQjI9hIwQWVGNbze1DwL9ZD
a38+KijlrBRtX3kcx2JQr1ofB892Hcs6NcDz7estIhsxG2KjK8yFJ4uSaf+iNCs/o5SE
/EErSXbo6NYdvJUTUXQQ949IMncoT1nP5SyZw89XreoKFfOeR+ijcsLdT1Z0+grVP4gc
U+ww==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=Vp/WxRNJpMQfioH05N4egSJpNowmnUxigvgfF/35crI=;
b=Kj3obkvREnNH56lc7PxVafVOppzAmGCT7ZYJmX59equ+vrQhwGjAKoYEasIsTGP4nj
bP2mHd7grE3PDOXh5VDLIJoMzWLFvqQSTge2jVORJ0XtVjw1M9ekDdQDtEe8VYJyUZf+
1YVe2P3I7aCl506ZhsToTWimbt0iler1+AcP6yQIjGl82sEBz+pvV6r+drS9id+r7Agn
rnPdT58tV0E55bexj8degvMJ1GGym7AGzPNiNyIYYGhC+F5obj5tmTw1fsgp6t6VoxLu
LIQIM9FduCpQSZpWXPEsNsoV0CUHOCyIlbQRNDEZVegbjvB8HZtUZVvy5T4Qxt3UfswW
fQFA==
X-Gm-Message-State: AOAM532z4M9vZRO6ChQD6b3p7GWA1TZvWgdJIqTqPmYWZoXCM8NKUGJ7
moZW7Za2eN+IhdHMf8MiVpR4BAOEbSWTdd9naLtVmfDZyFI=
X-Google-Smtp-Source: ABdhPJzkfO2TzUq+0+6Uekux+5ruuCaZVUZHTGRtYvI1rXtRM5azUA7lIiQKROccAGMEjTqQxix4YCvxCZAZzRIJGUU=
X-Received: by 2002:a92:3f0b:: with SMTP id m11mr17113575ila.265.1630333916438;
Mon, 30 Aug 2021 07:31:56 -0700 (PDT)
In-Reply-To: <sgipr7$946$1@ciao.gmane.io>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmqsmdTZe6QJF3y6Q72hvV5OXiD7CkTwj_pxArr3PQ5gTA@mail.gmail.com>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
<CAPTjJmousW_wqKQeYKK_xa6-3Qwo5S5NN+SoFtLOfyGe0iftGQ@mail.gmail.com>
<sgipr7$946$1@ciao.gmane.io>
 by: Chris Angelico - Mon, 30 Aug 2021 14:31 UTC

On Tue, Aug 31, 2021 at 12:28 AM Peter Otten <__peter__@web.de> wrote:
>
> On 30/08/2021 15:50, Chris Angelico wrote:
>
> > def how_many_times():
> > return next((count, rolls) for count, rolls in
> > enumerate(iter(roll, None)) if len(Counter(rolls)) == 1)
>
>
> That's certainly the most Counter-intuitive version so far;)

Thank you, I appreciate that :)

> > Do I get bonus points for it being a one-liner that doesn't fit in
> > eighty characters?
>
> Nah, but you'll get an honorable mention when you run it through
> pycodestyle without line break...
>

Are there any linters that warn against "unintuitive use of
two-argument iter()"?

ChrisA

Re: on writing a while loop for rolling two dice

<mailman.510.1630334705.4164.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19223&group=comp.lang.python#19223

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: __peter__@web.de (Peter Otten)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Mon, 30 Aug 2021 16:33:51 +0200
Lines: 11
Message-ID: <mailman.510.1630334705.4164.python-list@python.org>
References: <86r1edlqxw.fsf@jevedi.com> <sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<sgg0gh$13lk$1@ciao.gmane.io>
<6fcf22af-fbf8-7a7b-4123-16765d431758@DancesWithMice.info>
<sgiqtb$i0b$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 2XgDwujJno8kB+nzC8B8YQp8oxI5ZFCasqZ/Zga3inQQ==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.002
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'message-
id:@ciao.gmane.io': 0.09; 'received:ciao.gmane.io': 0.09;
'received:gmane.io': 0.09; 'received:list': 0.09; 'subject:two':
0.09; "(i'm": 0.16; 'from:addr:web.de': 0.16; 'real-world,': 0.16;
'received:116.202': 0.16; 'received:116.202.254': 0.16;
'received:116.202.254.214': 0.16; 'simulation': 0.16;
'subject:loop': 0.16; 'subject:while': 0.16; 'subject:writing':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.23; 'everyone':
0.29; 'header:User-Agent:1': 0.31; 'python-list': 0.32; 'header
:In-Reply-To:1': 0.33; 'subject:for': 0.33; 'mean': 0.37; 'does':
0.38; 'model': 0.60; 'your': 0.64; 'received:116': 0.71
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <6fcf22af-fbf8-7a7b-4123-16765d431758@DancesWithMice.info>
Content-Language: en-US
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgiqtb$i0b$1@ciao.gmane.io>
X-Mailman-Original-References: <86r1edlqxw.fsf@jevedi.com>
<sgff85$s6i$1@ciao.gmane.io>
<a2f62a43-3ca6-72ec-7c60-8dce1d59d3e2@DancesWithMice.info>
<sgg0gh$13lk$1@ciao.gmane.io>
<6fcf22af-fbf8-7a7b-4123-16765d431758@DancesWithMice.info>
 by: Peter Otten - Mon, 30 Aug 2021 14:33 UTC

On 30/08/2021 06:17, dn via Python-list wrote:

> OTOH the simulation of rolling n-number of dice, as would happen in the
> real-world, would be broken by making the computer's algorithm more
> efficient (rolling until the first non-equal value is 'found'). Does
> that mean the realism of the model dies?

You've got to ask your dietician...

(I'm sure everyone agrees that I should stop here. And stop I will)

Re: on writing a while loop for rolling two dice

<864kb3m4qi.fsf@jevedi.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19301&group=comp.lang.python#19301

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!4+bwgJ580lENslyh7E5FoA.user.46.165.242.75.POSTED!not-for-mail
From: hrouselle@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Thu, 02 Sep 2021 11:28:21 -0300
Organization: Aioe.org NNTP Server
Message-ID: <864kb3m4qi.fsf@jevedi.com>
References: <86r1edlqxw.fsf@jevedi.com>
<dice-20210828155623@ram.dialup.fu-berlin.de>
<86a6l1thz7.fsf@jevedi.com>
<4b8ed591-2f2f-6c76-4606-b431f52cf847@DancesWithMice.info>
<mailman.485.1630190573.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="11735"; posting-host="4+bwgJ580lENslyh7E5FoA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:sAZZY43vwjkZaghj2jf2BK/uRNw=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Hope Rouselle - Thu, 2 Sep 2021 14:28 UTC

dn <PythonList@DancesWithMice.info> writes:

> On 29/08/2021 08.46, Hope Rouselle wrote:
>> Here's my solution:
>>
>> --8<---------------cut here---------------start------------->8---
>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x != y:
>> c = c + 1
>> x, y = roll()
>> return c, (x, y)
>
>>
>> Why am I unhappy? I'm wish I could confine x, y to the while loop. The
>> introduction of ``x, y = 0, 1'' must feel like a trick to a novice. How
>> would you write this?
>
>> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>> """Rolls two dice until both yield the same value.
>>> Returns the number of times the two dice were rolled
>>> and the final value yielded."""
>>> roll_count = 0
>>> while True:
>>> outcome = roll_two_dice()
>>> roll_count += 1
>>> if outcome[ 0 ]== outcome[ 1 ]: break
>>> return roll_count, outcome[ 0 ]
>>
>> You totally convinced me. Thanks.
>
> On the other hand...
> whilst you expressed concern about the apparently disconnected 'set up'
> necessary before the loop, this solution adds a "True/Forever" and a
> "Break" construct, which some may deem not that much better (if at all)
>
> The idea of abrogating the while-condition but then adding another
> (disconnected) condition to break, seems to hold equal potential for
> confusion. or the type of dissatisfaction which motivated the original
> question!

Pretty well observed! Hats to you.

> Looking at that from the inside-out, the loop's contents perform two
> functions: the rolling and counting (per Statement of Requirements), but
> also a loop-controlling element. Thus the reader's question: "what does
> this loop do?" is conflated with "how many times does it do it?".

Well put.

> Let's go completely off-the-rails, why not use a never-ending range() to
> fuel a for-loop 'counter', and within that loop perform the dice-roll(s)
> and decide if it is time to 'break'. The range replaces the "True". The
> for-loops index or 'counter' will deliver the desired result.
>
> Neat? No!
> Readable? No!
> An improvement over the while-True? Definitely not!
> Yet, the mechanism is the same AND offers a built-in counter. Hmmm...

Yeah. Here's a little context. I came across this by processing a list
of exercises. (I'm teaching a course --- you know that by now, I
guess.) So the first thing I observed was the equal volume of work
dedicated to while loops and for loops --- so I decided to compared
which appeared more often in a certain sample of well-written Python
code. It turns out the for loop was much more frequent. Students have
been reporting too much work in too little time, so I decided to reduce
the number of exercises involving while loops. When I began to look at
the exercises, to see which ones I'd exclude, I decided to exclude them
all --- lol! --- except for one. The one that remained was this one
about rolling dice until a satisfying result would appear. (All other
ones were totally more naturally written with a for loop.)

So if I were to also write this with a for-loop, it'd defeat the purpose
of the course's moment. Besides, I don't think a for-loop would improve
the readability here.

But I thought your protest against the while-True was very well put:
while-True is not too readable for a novice. Surely what's readable or
more-natural /to someone/ is, well, subjective (yes, by definition).
But perhaps we may agree that while rolling dice until a certain
success, we want to roll them while something happens or doesn't happen.
One of the two. So while-True is a bit of a jump. Therefore, in this
case, the easier and more natural option is to say while-x-not-equal-y.

But this approach seems to force me into initializing x, y with
different values.

> Returning to the concern:
>
> x, y = 0, 1
> c = 0
>
> The first line is purely to ensure that the loop executes at least once,
> ie the two assigned-values are not 'real'. Hence the disquiet!
>
> Initiating the counter is unavoidable (@Chris' suggestion notwithstanding).
>
> However, remember that Python (like decent DBs) has a concept (and an
> idiom) of a value to be used when we don't (yet) know what the value
> is/should be! Further that Python allows such a value to be used in
> comparisons:
>
>>>> None != None
> False
>>>> None == None
> True
>
> Leading to:
>
> c, x, y = 0, None, None
> while ...
>
>
> Which solution reverts to the original loop-contents. which seem more
> obvious and thus more readable. (YMMV!)
>
> Simplicity over 'being clever'...

I don't see it. You seem to have found what we seem to agree that it
would be the more natural way to write the strategy. But I can't see
it. It certainly isn't

--8<---------------cut here---------------start------------->8---
def how_many_times_1():
c, x, y = 0, None, None
while x != y:
c = c + 1
x, y = roll()
return c, x, y
--8<---------------cut here---------------end--------------->8---

nor

--8<---------------cut here---------------start------------->8---
def how_many_times_2():
c, x, y = 0, None, None
while x == y:
c = c + 1
x, y = dados()
return c, x, y
--8<---------------cut here---------------end--------------->8---

What do you have in mind? I couldn't see it.

Re: on writing a while loop for rolling two dice

<86tuj3kpin.fsf@jevedi.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=19304&group=comp.lang.python#19304

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!i2pn.org!aioe.org!4+bwgJ580lENslyh7E5FoA.user.46.165.242.75.POSTED!not-for-mail
From: hrouselle@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on writing a while loop for rolling two dice
Date: Thu, 02 Sep 2021 11:42:24 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86tuj3kpin.fsf@jevedi.com>
References: <86r1edlqxw.fsf@jevedi.com>
<AM0PR07MB5700B075D74E8E85483C0BE587CB9@AM0PR07MB5700.eurprd07.prod.outlook.com>
<mailman.506.1630329121.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="25724"; posting-host="4+bwgJ580lENslyh7E5FoA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:HAngNwCDzf4C5eNEpSG130DwcWI=
 by: Hope Rouselle - Thu, 2 Sep 2021 14:42 UTC

David Raymond <David.Raymond@tomtom.com> writes:

>> def how_many_times():
>> x, y = 0, 1
>> c = 0
>> while x != y:
>> c = c + 1
>> x, y = roll()
>> return c, (x, y)
>
> Since I haven't seen it used in answers yet, here's another option using our new walrus operator
>
> def how_many_times():
> roll_count = 1
> while (rolls := roll())[0] != rolls[1]:
> roll_count += 1
> return (roll_count, rolls)

That's nice, although it doesn't seem more readable to a novice seeing a
while for the first time, seeing a loop for the first time, than that
while-True version. In fact, I think the while-True is the clearest so
far. But it's always nice to spot a walrus in the wild! (If you're
somewhere safe, that is.)


devel / comp.lang.python / on writing a while loop for rolling two dice

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor