Will You help with optimizing my code?

Will You help with optimizing my code?

from itertools import product
def probability(dice_number, sides, target):
counter=0
pomocnicza=[]


for p in product(list(range(1,sides+1)), repeat=dice_number):
pomocnicza.append(p)
pomocnicza= [x for x in pomocnicza if sum(x) == target]

counter=len(pomocnicza)

#my_list = [x for x in my_list if x.attribute == value]
return round(counter * 1.0 / (sides ** dice_number), 4)
if __name__ == '__main__':
#These are only used for self-checking and are not necessary for auto-testing
def almost_equal(checked, correct, significant_digits=4):
precision = 0.1 ** significant_digits
return correct - precision < checked < correct + precision

#assert(almost_equal(probability(2, 6, 3), 0.0556)), "Basic example"
#assert(almost_equal(probability(2, 6, 4), 0.0833)), "More points"
#assert(almost_equal(probability(2, 6, 7), 0.1667)), "Maximum for two 6-sided dice"
#assert(almost_equal(probability(2, 3, 5), 0.2222)), "Small dice"
#assert(almost_equal(probability(2, 3, 7), 0.0000)), "Never!"
#assert(almost_equal(probability(3, 6, 7), 0.0694)), "Three dice"
assert(almost_equal(probability(10, 10, 50), 0.0375)), "Many dice, many sides"

Don't use python

I have to, It's for class

kill yourself fag and start coding in C like a real adult

Go ask and put your code inside [code][/code] tags.

I will, thanks

you shouldn't be asking on Sup Forums for help for your school homework. what the fuck is wrong with you.

Do your own homework faggot

Dubs decides what language I learn next

...

French

Chinese

Check'd. Now start studying,

He,asked for dubs, not trips newfag

But trips are dubs, just like how squares are rectangles.

Squares are rectangles because they have 4 sides, dubs is two sequentially repeating digits, trips is 3 , ergo dubs!= trips

nice dubs

Dubs aren't trips but trips are dubs

you mean c#
corporations want fast development. No one cares about memory these days.
And c is now used mainly, for games, hardware, drivers and IOT devices.

What about languages like R or julia?

R is made for scientists. it is god awful. it is slow and memory intensive because all the library's where written by people that had no clue how to write efficient programs.

So what would you recommend to crunch and visualize data?

python.
You can use R just don't build applications with it that your entire company will use.

/thread

>he fell for a meme language

Why is everyone else itt saying not to use python?

HolyC

because they think it's not a programming language. Sure it isn't as fast as the other languages, but you can create your stuff faster in it. The 2 main languages used for number crunching today are R and python.

Other languages will be more efficient, but your time is also important, it will take you at least 4 times as long in other languages to program your program and set everything up.

If you have infinite time, you can create something from scratch, but if your time is important and hardware isn't a limiting factor use R or python