sandbox/python: fix 5 and 9 and use more generators