#task1 = "https:\w0111ww.r89&73iplex20%9*7&&8778.com" #task1 = "h78787787454224ttps://st11a8937408909-808778078087*&)(&*^&*()&^*&*()_?><>?,/,/,ckoverflow.com" #task1 = "htt&6ps:www.a$$$###^^^rsen&&66$al%%%%343*7^^^.com" # This function is to make a url readable by removing all special characters and numbers from the url def readable (task): new = [] #list of all special characters and numbers unwanted_char = ["*","'", '"',"%", "!", "@", "#", "$","^","&", "(", ")", "_", "-", "+", "=", "[", "]", "{", "}", "|", ";", "?", "/", ">", "<", ",", "`", "~", "0","1","2","3","4","5","6","7","8","9"] task_split = list(task) # this line breaks individual characters for item in task_split: # This for-loop and if statement checks if the each letter in the string is a special character if item not in unwanted_char: new.append(item) # the line adds the every character that is not a special character to the empty list new else: new.append(item) # this line adds the special character to the list new.pop() # this line pops it back out result = "".join(new) # This line joins the individual characters back together to become one string again # The follow structure adds the required space before the .com dotcom_index = result.find(".com") # This line looks for the where the .com is in the string result = result[:dotcom_index] + " " + result[dotcom_index:] # this line breaks the string from where the .com is and add space return result # This finally returns the result test = readable(task1) print (test)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question