If you're doing this to make filenames safe, you'll have to deal with unicode as well, e.g. `хелло ворлд` should become `hello-world`. There's a package called [python-slugify](https://github.com/un33k/python-slugify) that should do the trick.