rewrite pythonicly