Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to ignore the first \ in a string in a continuous sequence by using regex. So that when there is only \, we will not match it. When there are two \\, we only match one \.
For example:
I got:
{\"url\":\"http:\\/\\/p1.pstatp.com\\/origin\\/tuchong.fullscreen\\/29016715_tt\"}
what regex I can use to make it become:
{"url":"http:\/\/p1.pstatp.com\/origin\/tuchong.fullscreen\/29016715_tt"}
How to make this happen?
This regex should suit your needs :
(?<!\\)\\
See this demo here.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I wanted to calculate this mathematical expression in python3:
Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369
But I'm getting this wrong result: 4.2690044488402846e+45 . Is there something wrong in the expression? how can I fix it to give me the right result?
I think you might be confused because it is showing scientific notation? '{}'.format() should help in that case.
Xi = (70 + 1344736401384689745317259585614247891453883777111/315)% 115792089210356248762697446949407573529996955224135760342422259061068512044369
print('{0:f}'.format(Xi))
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Given this dictionary:
my_dict={'animal':['Dog','Cat'],'age':[4,5],'bark':[True,False],'badge_num':['234','896']}
what code will cast 'age' to float?
you could use map combined with float like the following:
my_dict['age']=list(map(float, my_dict['age']))
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
When I run
print(c)
I get the output
[45]
How do I remove the [ ] and get output like this as an integer?
45
Because I want to print this but It won't run.
print(b[c:c+50])
Take the first element of that array.
print(c[0])
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I need to parse a text but the problem with it is that words which I am looking for are not on only one line.
For example the word computer can have "comp" at the end of the line and at the beginning of the line I have "uter" (without any white spaces). I want to print that I have found the word "computer"
Which is the best solution to do it, taking into account that I need an optimized algorithm, not something that checks for each letter in the word computer.
Try using this kind of format:
word in "".join(line.strip() for line in text)
Here is a demo
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to check matches given string to the pattern.
Input may look like this: 3256-10wyput
So we've used this pattern [0-9]{4}\-[0-9a-z]{7}
I want to prepare an if statement which checks does input suit to my regex.
Pseudo code looks like that:
if regex in string:
return True
How it should look like?
Thanks for advices.
B.
You want to do a check with the re.match() function:
import re
if re.match('[0-9]{4}-[0-9a-z]{7}', '3256-10wyput'):
return True