replace

What is the most pythonic way of replacing values in nested lists?

What is the most pythonic way of replacing values in nested lists? Question: I have a list of strings, and I want to replace each ‘X’ and ‘O’ with True and False – turning each string into a list of booleans. arr = [‘XOOXO’, ‘XOOXO’, ‘OOOXO’, ‘XXOXO’, ‘OXOOO’] temp_list = [] bool_lists =[] for str …

Total answers: 2

read file and replace substrings in python

read file and replace substrings in python Question: I am trying to read a text file with python and remove certain strings from it. I have written a script, but for some reason it does not do what I would expect. As a minimal example I have the following text file named test.txt Here some …

Total answers: 2

How do I replace slaces in python

How do I replace slash character "'' by backslash character "/" in python Question: I need to replace forward slash "" with backward slash "/". I have tried: c = "/r/tes/integrtest_Ame.txt" x = c.replace("", "/") print(x) But I have got the error: File "C:Usersbwar1korDesktopTesttest.py", line 33 x = c.replace("", "/") ^ SyntaxError: EOL while scanning …

Total answers: 1

Replacing a word in a file to add another file content

Replacing a word in a file to add another file content Question: Input file (csv). NAME,TYPE,ACCESS_TOKEN dev765,datatype,Token765 dev879,datatype,Token879 Append file: { "file": "string", "mapping": { "columns": [ { "type": "NAME" }, { "type": "TYPE" }, { "type": "ACCESS_TOKEN" } ], "delimiter": ",", "header": true, "update": true } } The goal is to replace the "string" …

Total answers: 1

How do I replace characters in a list of strings with a different character?

How do I replace characters in a list of strings with a different character? Question: I am making a platformer with enemies and want to have enemies randomly placed on the map. My map contains lists of strings that specify the map tiles. Basically I just want to randomly put the letter ‘E’ on a …

Total answers: 1

Replacing Overlapping Regex Patterns in Python

Replacing Overlapping Regex Patterns in Python Question: I am dealing with trying to make a .ttl file I was handed digestible. One of the issues is that the rdfs:seeAlso values are not sanitized and it breaks down downstream programs. What I mean by this is that there are links of the form: rdfs:seeAlso prefix:value_(discipline) In …

Total answers: 3

Randomly changing letters in list of string based on probability

Randomly changing letters in list of string based on probability Question: Given the following data = [‘AAACGGGATTn’,’CTGTGTCAGTn’,’AATCTCTACTn’] For every letter in a string not including (n), if its probability is greater than 5 (i.e. there is a 50% chance for a change), I’d like to replace the letter with a randomly selected letter from options …

Total answers: 2