on writing a while loop for rolling two dice

dn PythonList at DancesWithMice.info
Sun Aug 29 19:52:18 EDT 2021


On 29/08/2021 22.24, Chris Angelico wrote:
> On Sun, Aug 29, 2021 at 8:14 PM dn via Python-list
> <python-list at 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


More information about the Python-list mailing list