나는 이렇게 학습한다/Algorithm & SQL

Remove anchor from URL

daco2020 2022. 8. 9. 18:46
반응형

Complete the function/method so that it returns the url with anything after the anchor (#) removed.

Examples

"www.codewars.com#about" --> "www.codewars.com"
"www.codewars.com?page=1" -->"www.codewars.com?page=1"

 

 

Solution:

def remove_url_anchor(url):
    i = url.find("#")
    return [url, url[:i]][i!=-1]

 

 

Order Solution:

def remove_url_anchor(url):
  return url.split('#')[0]
def remove_url_anchor(url):
  return url.partition('#')[0]
def remove_url_anchor(url):
  import re
  return re.sub('#.*$','',url)
from urllib.parse import urldefrag
def remove_url_anchor(url):
    return urldefrag(url).url

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

List Filtering  (0) 2022.08.11
Sum of a sequence  (0) 2022.08.10
Find the unique number  (0) 2022.08.08
Fix string case  (2) 2022.08.07
Factorial  (0) 2022.08.07