Strip A specific part from a url string in python

Advertisements Im passing through some urls and I’d like to strip a part of it which dynamically changes so I don’t know it firsthand. An example url is: https://…?pid=2&gid=lostchapter&lang=en_GB&practice=1&channel=desktop&demo=2 And I’d like to strip the gid=lostchapter part without any of the rest. How do I do that? >Solution : You can use urllib to convert… Read More Strip A specific part from a url string in python

.strip() function taking off first letter of string when it shouldn't

Advertisements I have a string that I’m trying to strip the last camel cased word off if it matches any of these words specified in the regex by doing my_string = ‘myFileCins’ my_string.strip("(Cins)?(V2)?(Fitch)?$") This returns ‘myFile’ which is fine. However it looks like if the string starts with the letter "c" (based on my testing)… Read More .strip() function taking off first letter of string when it shouldn't

Why this replace(), re.sub() or strip() do not work with this string?

Advertisements I’m using BeautifulSoup to get a result from a webpage. I’ve transformed the data object to string and I’m not being able to trim it. I’ve got the following string: text = ‘\n\n\n This product is not available.\n \n’ I’ve tried three options to start removing the newline character: string=text.replace(‘\n’,”) string=text.strip(‘\n’) import re string… Read More Why this replace(), re.sub() or strip() do not work with this string?

How can I convert text to columns with Python?

Advertisements I have this data: Event|Time|Meta|Meet|Date 50 Y Free|22.30|U|IL NASA Winter Blast Off|Nov 30, 2018 100 Y Free|55.50|U|Greg’s Super Splash|Jun 16, 2011 50 Y Breast|27.07|X|CCIW Swimming Championships|Feb 10, 2006 50 L Breast|33.70||1st Cyprus International Masters Swim Meet|Oct 22, 2016 100 Y Breast|58.97||CCIW Swimming Championships|Feb 10, 2006 100 L Breast|1:14.24||42nd Bulgarian Masters Championship|Sep 07, 2020 200… Read More How can I convert text to columns with Python?

How to strip/remove certain characters from a lsit

Advertisements I am currently trying to remove certain characters recursively from a list. I have a list: lst1 = [‘ZINC1_out.pdbqt’, ‘ZINC2_out.pdbqt’, ‘ZINC3_out.pdbqt’] I would like to remove the ‘_out’ so that the list looks like this >>lst1 [‘ZINC1.pdbqt’, ‘ZINC2.pdbqt’, ‘ZINC3.pdbqt’] My current code looks like this: lst1 = [‘ZINC1_out.pdbqt’, ‘ZINC2_out.pdbqt’, ‘ZINC3_out.pdbqt’] for i in lst1:… Read More How to strip/remove certain characters from a lsit

Splitting a string into elements creates a space that I can't remove

Advertisements I have a data frame with a column for ‘genre’ with strings like ‘drama, comedy, action’. I want to split the elements like this ‘drama’, ‘comedy’, ‘action’ so I’ve used; Genre=[] for genre_type in books[‘genre’].astype(‘str’): Genre.append(genre_type.split(‘,’)) genre[‘genres_1′]=genres_1 but, the result contains spaces between genres (other than the first one listed) like ‘drama’,’_comedy’,’_action’. (I used… Read More Splitting a string into elements creates a space that I can't remove