help how to sort a list in order of 'n' in python without using inbuilt functions??

Chris Angelico rosuav at gmail.com
Sun May 26 00:02:29 EDT 2013


On Sun, May 26, 2013 at 1:09 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> You're right, all my dice are eight-sided and complex:
>
> 1+0i
> 1+1i
> 1-1i
> -1+0i
> -1+1i
> -1-1i
>
>
> :-)

Now THAT is a dice of win!

>> Now, I have here with me
>> a set used for maths drill (to be entirely accurate, what I have here is
>> the company's stock of them, so there are multiples of each of these -
>> anyone need to buy dice?)
>
> Are you serious? What's the cost, posted to Melbourne?

$1 each, postage probably $5 for any number. Or there may even be
option to pick up / hand deliver, depending on where in Melb you are.

http://www.kepl.com.au/ - company's winding down, but we still have stock.

> Oh, you mean ÷ (division sign)! Why didn't you say so? :-P

I tend to stick to ASCII in these posts. :)

> And another thing, shame on you, you mean × not x. It's easy to find too:
>
> py> from unicodedata import lookup
> py> print(lookup("MULTIPLICATION SIGN"))
> ×

I'm aware of that, but see above, I stick to ASCII where possible. The
faces would be better represented with some of the other digits (the
bolded ones, perhaps), but I used the ASCII digits. :)

>> Plus, if you roll 2d6 (that is, two
>> regular six-sided dice and add them up), 7 is statistically the most
>> likely number to come up with. Therefore it IS random.
>
> Yes, but if you subtract them the most common is 0, if you multiply the
> most common are 6 or 12, and if you divide the most common is 1. If you
> decide on the operation randomly, using the +-×÷+ die above (ignoring
> wildcards), the most common result is 6. The probability of getting a 7
> is just 1/15.
>
> from collections import Counter
> from operator import add, sub, mul, truediv as div
> ops = (add, sub, mul, div, add)
> Counter(op(i, j) for op in ops for i in range(1, 7) for j in range(1, 7))

LOL! I never thought to go THAT far into the analysis..... Nice one!

ChrisA



More information about the Python-list mailing list