0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Codewars 5 kyu Extract the domain name from a URL

Posted at

Codewars 5 kyu Extract the domain name from a URL

https://www.codewars.com/kata/514a024011ea4fb54200004b/train/python
Task
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example:

Verbalization

replace “http://” to “”
replace “https://” to “”
Replace “www.“ to “”
Extract left side of “.”
idx = s.find(“.”) #find the index of “.”
r = s[:idx] # slice the index of “.”

Code

def domain_name(url):
    name = url.replace("http://","").replace("https://","").replace("www.","")
    idx = name.find(".") 
    name = name[:idx]  

    return name

Reference

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?