I have such a method which takes a URL, such as http://twitter.com/ttt or twitter.com/dasd, and should show its domain with http: http://twitter.com and name twitter
def show_domain(url):
sites = {
'twitter': ['http://www.twitter.com/', 'twitter'],
'facebook': ['http://www.facebook.com/', 'facebook'],
'pininterest': ['http://www.pininterest.com/', 'pininterest']
}
if sites['twitter'][0] in url:
link = sites['twitter'][0]
brand = sites['twitter'][1]
elif sites['facebook'][0] in url:
link = sites['facebook'][0]
brand = sites['facebook'][1]
else:
link = sites['pininterest'][0]
brand = sites['pininterest'][1]
return link, brand
Is there way to optimise this code?
urlparse
module? \$\endgroup\$