I have a string ,for example s = “-1+2-3” I want to replace all – to + and all + to -. what I expected is s = +1-2+3 .So I can’t just use s.replace(‘-‘,’+’).replace(‘+’,’-‘),because it return s=-1-2-3,maybe a for loop can help. But I wonder if there is a pythonic way to do so? thanks for all solutions i
Tag: string
Find and remove slightly different substring on string
I want to find out if a substring is contained in the string and remove it from it without touching the rest of the string. The thing is that the substring pattern that I have to perform the search on is not exactly what will be contained in the string. In particular the problem is due to spanish accent vocals
How to get rid of b’ , all these x00, x** like things in bunch of strings in python 3.6?
I have strings as below: I want to get rid of all these b’ and anything with x with 2 trailings like xe2, x80 and so on. I dont know how to get rid of it. I tried But because content is already str, I can’t decode. So I tried below to make it like bytes and get rid of
Pandas Column Split but ignore splitting on specific pattern
I have a Pandas Series containing Several strings Patterns as below: I would like to split and explode it such that the result would be as follows: In order to do the explode I need to first split. However, if I use split(‘,’) that also splits the items between [] which I do not want. I have tried using split
Python: Replace characters in string at different positions with arguments
It’s a simple question. I have a generic string and I want to replace an asterisk * with arguments provided. If I shall give two arguments (‘Berlin’,’Germany’), I should get It’s an easy problem, and I can solve it, but I am looking for one line solution where every positional argument replaces the corresponding *. I think, I have seen
Shift for uppercase letters
I am writing a program on shifting a word. My desired output should be a:f b:g c:h … y:d z:e A:F B:G C:H … Y:D Z:E But after running this code, my output is a:f b:g c:h … y:d z:e A:f B:g C:h … Y:d Z:e Seems isupper() function didn’t work here. Could you help with this based on my
Advanced string manipulation in Python
I’m trying to get only the value that are after the string 2021 from the following string: I need to get those 2 values separated (first one has to be 168088000000 and the second one has to be 61271000000 in this case). They have to be preceded by 2021 (and the result should give only the 2 numbers I mentioned
Remove duplicate substring at the start of the string
I would like to remomve duplicate substrings at the start of a string where a duplicate exists. I sort of have the logic working for the first row (see below) but am quite new to Python so am struggling to produce code which will apply the same logic for a rows in a larger dataset. Below is an example of:
Python 3: How do I add input and a string to the same line?
I have to put the input on the same line as the string and can’t figure out how. Here’s the code: Answer The function input() takes in a string to print so you can do this: And it will print the string before taking input without adding a newline
How do you change a string that is already in the console?
I’m trying to make a typing thingy where you type what time delay you would like and what the string you want to output is and then it slowly types each letter: I just have one problem. I want the string to output in one line but each letter at a different time, but I can only make it so