Python code for general purposes