string

How can I programmatically build a string containing escaped characters to pass as an argument to a function in Python?

How can I programmatically build a string containing escaped characters to pass as an argument to a function in Python? Question: I am trying to build the string below programatically: string0 = ‘case when "LETTER" in (‘a’,’b’) then "LETTER" else ‘other letter’ end’ I do: a_list = [‘a’,’b’] string = ‘(\”+’\’,\”.join(a_list)+’\’)’ string2 = ‘case when …

Total answers: 5

Re-sort string based on precedence of separator

Re-sort string based on precedence of separator Question: I have a string with a certain meaning for example "a,b;X1" or e&r1. In total there are 3 possible separators between values: ,;& where ; has low precedence. Also "a,b;X1" and "b,a;X1"are the same but to be able to compare they are the same, I want to …

Total answers: 3

Splitting a string into new lines based on specific number of characters

Splitting a string into new lines based on specific number of characters Question: I would need to split a string in new lines based on the number of characters included in a list: num_char=[14,12,7] # the list is actually longer: this is just an example text = "Hello everyone how are you? R u ok?" …

Total answers: 3

Python Vectorization Split String

Python Vectorization Split String Question: I want to use vectorization to create a column in a pandas data frame that retrieve the second/last part of a string, from each row in a column, that is split on ‘_’. I tried this code: df = pd.DataFrame() df[‘Var1’] = ["test1_test2","test3_test4"] df[‘Var2’] = [[df[‘Var1’].str.split(‘_’)][0]][0] df Var1 Var2 0 …

Total answers: 3

String variable not behaving correctly in json.dumps

String variable not behaving correctly in json.dumps Question: I’ve got an API request I am sending and I gather the necessary data and compile it in the proper format into a string called compiled_string. When I try to include it in json.dumps, it is being changed so that my API request is not working properly. …

Total answers: 1

Showing new lines(n) in PD Dataframe String

Showing new lines(n) in PD Dataframe String Question: I am trying to create a dataframe that has one column that contains a string of texts that has lines. Those lines are separated by lines so that they are easily readable. string=[”’ hello all:. I request the following from you: do the laundry: sleep early wake …

Total answers: 3

How to convert string to binary for setpassword() function in Python

How to convert string to binary for setpassword() function in Python Question: This code writes to a string-type password random numbers and symbols. Then create a zip file and write there another zip file and then It needs to set a password to the zip file, but It wants a bin type, not a string …

Total answers: 1

how to get a value from a string line of a file

how to get a value from a string line of a file Question: I have a log file which contains multiple lines and I want to get the value of the string WorkerThreads="20" from specific line of the below log content 10000 2aa0 03/29 17:02:30 ### Context="cvd.exe" Module="ThreadPool" Instance="cvstatanalysis" Type="Delta" TaskAdded="0" TaskDone="0" 10000 2aa0 03/29 …

Total answers: 1

Group a list of strings by similar values

Group a list of strings by similar values Question: I want to group a list of strings by similarity. In my case (here simplified cause this list can be huge) it’s a list of path to zip files like this: ["path/002_AC_HELICOPTEROS-MARINOS_20230329_210358_145T3_21049_00748_DMAU.zip", "path/002_AC_NOLAS_20230326_234440_145T2_20160_06473_VMS_UMS.zip", "path/002_AC_HELICOPTEROS-MARINOS_20230329_211105_145T3_21049_00748_FDCR.zip", "path/002_AC_HELICOPTEROS-MARINOS_20230329_205916_145T3_21049_00747_VMS_UMS.zip", "path/002_AC_NOLAS_20230326_235504_145T2_20160_06473_FDCR.zip"] I would like to group the strings in that list …

Total answers: 2