A more Pythonic version.