This question already has answers here:
How to use string.replace() in python 3.x
(9 answers)
Closed 5 years ago.
I am trying to write a program that replaces every 'a' for '&'.I am currently stumped and was wondering if someone could write it for me to get an idea of what it would look like. Thanks.
strw = "kabhi kabhi mery dil main khyaal aata hy"
print (strw.replace("a", "&"))
Related
This question already has answers here:
Is it possible to access original function which has been overwritten in python [duplicate]
(3 answers)
Closed 4 months ago.
I'm doing maintenance on a huge file that follows like this
...stuff
def open(account):
...do stuff
...stuff
However I need to write a str to a txt, so I was gonna do the following
with open(filename,"a") as file:
file.write(mystr)
and this is calling the open(account) method, which is being used in a lot of classes, so renaming is not an option, how can I call the open method from the built-in functions from python and not the one with the same name?
You can do __builtins__.open().
This question already has answers here:
How do I do a case-insensitive string comparison?
(15 answers)
Closed 7 months ago.
I’m new with Python. Just One question.
I try to create a mini quizz game and i want avoid this :
Answer = Input(« « « Who sing : « Thriller » ? » » »)
If answer == « Michael Jackson »:
Print(« Good. »)
Else:
Print(« Wrong. »)
The problem is that if the user answer «michael jackson », the code run with wrong.
How can i fixed that?
Thanks
The way that this is usually done is to just turn all the input to lowercase. This can be done with the .lower() method on the input string. The corrector answer would then be "michael jackson".
This question already has answers here:
Regular expression to stop at first match
(9 answers)
Python non-greedy regexes
(7 answers)
Closed 2 years ago.
Consider following code:
import re
mystring = "\enquote {aaa} a \enquote {bbb}"
text = re.sub(r"\\enquote \{(.+)\}", r"\1", mystring)
print(text)
is outputing:
"aaa} a \enquote {bbb"
but I am acrually trying to achieve output of:
"aaa a bbb"
What have I misunderstood?
Background: I am trying to do some simple conversion from LaTeX format to general text, for which I need to replace LaTeX commands, but retain raw text itself (and sometimes do also some actual replacing). So how can I do group capture in python?
This question already has answers here:
How to pass all arguments passed to my Bash script to a function of mine? [duplicate]
(7 answers)
Closed 5 years ago.
I need to create a function and pass an argument like
myfunc word_100
and then the output should display
word_101
Basically it should increment taking in account the delimiter. I am thinking to say put word as one variable and the number and increment the number and combine it together. But not sure how to go about.
Try:
NAME=${1%_*}_
NUM=${1##*_}
echo $NAME`expr $NUM + 1`
This question already has an answer here:
How to convert a jQuery filter for use with waitForKeyElements?
(1 answer)
Closed 7 years ago.
So far i have this code:
$('.js-stream-item:has(span.ProfileTweet-action--retweet:has(span.ProfileTweet-actionCount[data-tweet-stat-count="0"]))').toggle();
It works fine but only remove tweets with 0 retweets, how can i use the attribute "data-tweet-stat-count" by condition ?
Thanks in advance.
I think you could do something like this:
$('div.stream-item-footer:has(span.action-retweet:has(span.actionCount))').filter(function() {
return parseInt($(this).find('span.actionCount').attr('data-tweet-stat-count')) >= 3;
}).toggle();