PYTHON: recursive pattern