min() arg is an empty sequence

If you want to avoid this ValueError in general, you can set a default argument to min(), that will be returned in case of an empty list. See described here. Note that this only works in Python 3.4+

Pop index out of range

To get the final value of a list pop’ed, you can do it this way: Keep in mind that pop removes the item, and the list changes length after the pop. Use negative numbers to index from the end of a list that may be changing in size, or just use pop() with no arguments for the … Read more

ImportError: No Module Named bs4 (BeautifulSoup)

Activate the virtualenv, and then install BeautifulSoup4: When you installed bs4 with easy_install, you installed it system-wide. So your system python can import it, but not your virtualenv python. If you do not need bs4 to be installed in your system python path, uninstall it and keep it in your virtualenv. For more information about virtualenvs, read this

printing a two dimensional array in python

A combination of list comprehensions and str joins can do the job: yields Using for-loops with indices is usually avoidable in Python, and is not considered “Pythonic” because it is less readable than its Pythonic cousin (see below). However, you could do this: The more Pythonic cousin would be: However, this uses 30 print statements, whereas my original answer uses just one.

In Python how should I test if a variable is None, True or False

keep it simple and explicit. You can of course pre-define a dictionary. If you plan on modifying your simulate function to include more return codes, maintaining this code might become a bit of an issue. The simulate might also raise an exception on the parsing error, in which case you’d either would catch it here or let it propagate … Read more