May-17-2020, 08:31 AM
Hi all,
I'm trying to take some string, stri_ , and iterate through it until I find a particular character. Then, I will update the stri_ to be stri_ with that character and everything after it removed.
The above works fine in most cases, however I ran into problems with the below.
Is there any way I can do something similar to rstrip(), but instead of removing a single character, remove every character rstrip() checked before it found "." ie. the last "." in the string?
Thanks,
K
I'm trying to take some string, stri_ , and iterate through it until I find a particular character. Then, I will update the stri_ to be stri_ with that character and everything after it removed.
1 2 3 4 5 |
# Working with url_ , a string of any length url_ = url_[:url_.find( "." )] # For url_ == "wikipedia.com", url_ should become "wikipedia". print (url_) # wikipedia |
1 2 3 4 5 |
# Working with url_ , a string of any length url_ = url_[:url_.find( "." )] # For url_ == "en.wikipedia.com", url_ should become "en.wikipedia". print (url_) # en |
Thanks,
K