optimize sanitize.py

Remove unneeded list cast.
Add doc string.
Use join instead of format.