Skip to content

Latest commit

 

History

History
66 lines (38 loc) · 848 Bytes

Remove_anchor_from_URL.md

File metadata and controls

66 lines (38 loc) · 848 Bytes

CodeWars Python Solutions


Remove anchor from URL

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

Examples

# returns 'www.codewars.com'
remove_url_anchor('www.codewars.com#about')

# returns 'www.codewars.com?page=1'
remove_url_anchor('www.codewars.com?page=1')

Given Code

def remove_url_anchor(url):
    # TODO: complete

Solution 1

def remove_url_anchor(url):
    return url[:url.find("#")] if "#" in url else url

Solution 2

def remove_url_anchor(url):
    return url.split("#")[0]

Solution 3

def remove_url_anchor(url):
    import re
    return re.sub('#.*$','',url)

See on CodeWars.com