pythonw.exe or python.exe?

If you don’t want a terminal window to pop up when you run your program, use pythonw.exe;Otherwise, use python.exe Regarding the syntax error: print is now a function in 3.xSo use instead:

Python map object is not subscriptable

In Python 3, map returns an iterable object of type map, and not a subscriptible list, which would allow you to write map[i]. To force a list result, write However, in many cases, you can write out your code way nicer by not using indices. For example, with list comprehensions:

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

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

TypeError: ‘dict_keys’ object does not support indexing

Clearly you’re passing in d.keys() to your shuffle function. Probably this was written with python2.x (when d.keys() returned a list). With python3.x, d.keys() returns a dict_keys object which behaves a lot more like a set than a list. As such, it can’t be indexed. The solution is to pass list(d.keys()) (or simply list(d)) to shuffle.