Useful python functions (possibly other code in due course) - e.g. text manipulation