Skip to content
Advertisement

Tag: string

pythonic way to replace two character in a string

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

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:

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

Advertisement