I'm involved in a web project. I have to choose the best ways to represent the code, so that other people can read it without problems/headaches/whatever.
The "problem" I've tackled now is to show a nice formatted url (will be taken from a "title" string).
So, let's suppose we have a title, fetched from the form:
title = request.form['title'] # 'Hello World, Hello Cat! Hello?'
then we need a function to format it for inclusion in the url (it needs to become 'hello_world_hello_cat_hello'), so for the moment I'm using this one which I think sucks for readability:
str.replace(title, ' ', '-').str.replace(title, '!', '').str.replace(title, '?', '').str.replace(string, ',' '').lower()
What would be a good way to compact it? Is there already a function for doing what I'm doing?
I'd also like to know which characters/symbols I should strip from the url.