Python rewrite - Initial Code