added Simon Taylors more generic python version