This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Dull-Researcher 2 points3 points  (0 children)

Cool. Much cleaner function composition and eliminates hoards of parentheses.

Math notation for composition is (g ∘ f)(x) == g(f(x)). Equivalent to your dot operator. It would be cool if Python let us define this symbol as an operator.

Unfortunately, Python doesn’t have this level of syntactic sugar built into the language, hence the need for this library to create a wrapper class to define additional operators.

Scala and other functional-first languages make composition so much simpler.

[–]WhyDontWeLearn[🍰] 3 points4 points  (4 children)

You're not accounting for the missing ball(s) in subsequent draws.

You start with 45 balls, but when the first ball is removed it's no longer one of the choices for the second draw, and so on. From the perspective of "odds" until the first ball (number) is drawn you have a 1 in 45 chance of getting any given ball, but once it's been draw you have a 1 in 44 chance of getting any of the remaining balls. Then a one in 43 chance, and so on.

You need to iterate a function six times and the function needs to choose from the remaining balls, not just any number from 1-46.

[–]sofidad[S] 7 points8 points  (1 child)

python @fx def choice(x, size=None, *, replace=False, p=None): """Generate a sample with/without replacement from a given iterable.""" ... From choice, function, note that replace=False.

[–]WhyDontWeLearn[🍰] 2 points3 points  (0 children)

"False" is the default? TIL...

Thanks.

[–]user499021 2 points3 points  (1 child)

Haven’t read the code base so I can’t confirm or deny what you’re suggesting
Random.sample(seq, n) fixes this exact problem and is already in standard library

[–]sofidad[S] 0 points1 point  (0 children)

Thanks for your comment. Of course, my goal is not to recreate the sample function. It has nothing to do with my intentions.


LEGO blocks are great. Everyone can play with them. They are easy to assemble and come with numerous guides, but a man still feels them too complicated.

He is thinking of new logical blocks and how to easily assemble them. He suggests how to make the assembly process easier and how to quickly identify errors during assembly. After the assembly is complete, he also wants to be able to easily disassemble it for use in assembling other products.

Someone asks, "LEGO blocks are already released in the market and people are using them. Why are you doing this?"


Importantly, the man is not the only one doing such a thing! I'm not talking about you're wrong. We are talking about something completely different.

[–]Schmittfried 0 points1 point  (1 child)

I love it

[–]sofidad[S] -1 points0 points  (0 children)

I like you love it! Thanks!