Here is a block of inefficient Python code. Walk me through how you would refactor it to improve runtime and readability.