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 7 kyu Remove anchor from URL

Last updated at Posted at 2025-02-12

7 kyu Remove anchor from URL
https://www.codewars.com/kata/51f2b4448cadf20ed0000386/train/python
Complete the function/method so that it returns the url with anything after the anchor (#) removed.

Verbalization

  1. If there is no #, return url (use if "#" in url: )
  2. Search the index number of #. (use url.index(#))
  3. Select words from first index to one before index of # (use[0:i(ndex of #)])

Code

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

Reference

#other solution

def remove_url_anchor(url):
  return url.split('#')[0]
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?