Find all files with the extension .py, sort them in reverse order, and then use xargs to run the sed command to replace all occurrences of 'foo' with 'bar' in each file.
find -name '*.py' | sort -r | xargs sed -i -e 's/foo/bar/g'