Python Binomial Coefficient

This question is old but as it comes up high on search results I will point out that scipy has two functions for computing the binomial coefficients: scipy.special.binom() scipy.special.comb()import scipy.special # the two give the same results scipy.special.binom(10, 5) # 252.0 scipy.special.comb(10, 5) # 252.0 scipy.special.binom(300, 150) # 9.375970277281882e+88 scipy.special.comb(300, 150) # 9.375970277281882e+88 # …but with `exact … Read more

Where do I get a SECRET_KEY for Flask?

The secret key is needed to keep the client-side sessions secure. You can generate some random key as below: Just take that key and copy/paste it into your config file See Sessions documentation

How to strip all whitespace from string

Taking advantage of str.split’s behavior with no sep parameter: If you just want to remove spaces instead of all whitespace: Premature optimization Even though efficiency isn’t the primary goal—writing clear code is—here are some initial timings: Note the regex is cached, so it’s not as slow as you’d imagine. Compiling it beforehand helps some, but … Read more

Is there a way to specify which pytest tests to run from a file?

You can use -k option to run test cases with different patterns: This will run test cases with name test_001 and test_some_other_test deselecting the rest of the test cases. Note: This will select any test case starting with test_001 or test_some_other_test. For example, if you have test case test_0012 it will also be selected.