Wednesday, February 6, 2019

codingdirectional: Remove the string after the # mark in a website url

We are supposed to start a new project today but because I still need a few more days to prepare for it, therefore, I have posted another question and answer session in this website just to get the thing going. This question again comes from the codewars website and it goes like this.

Given a url, stripes everything after the # mark. The solution to this question is fairly simple. If that url contains the # mark, the program will remove all the characters after the # mark and returns the new url or else the original url will be returned.

def remove_url_anchor(url):
   
    index = url.find('#')
    if(index != -1):
        return url[0:url.find('#')]
    else:
        return url

We will continue to solve more python questions until the tutorial’s material for the new project is fully ready.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...