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
I am trying to put in 2 inputs then get them as an output, but I cant seem to get a space between them at the end . I have tried a + sign, space between x and y, and a comma and none work.
A formatted string will work nicely here.
We can provide variables to a string that has special format markers, like so:
print('{0} {1}'.format(word1, word2))
Or, more easily, a string concatenation:
print(word1 + ' ' + word2)
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 5 days ago.
Improve this question
The whitespace should be replaced with a 'dollar' sign.
Keep the punctuation marks unchanged.
Note: Convert the given input sentence into lowercase before encrypting.
The final output should be lowercase.
input = Hello World
expected_output = svool$dliow
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 12 months ago.
Improve this question
How can I replace double quotes inside single quoted sections with something like \"?
Given this text:
{['abc.abc',"dsa",asd:'<td id="ssa" width="2px" class="odd-column">']}
I want it to be:
{['abc.abc',"dsa",asd:'<td id=\"ssa\" width=\"2px\" class=\"odd-column\">']}
In a later step I will replace all single quotes to get proper json for convertion.
Here is a python script which does what you are asking for.
We have to escape all the " and \
import re
string = r"""{['abc.abc',"dsa",asd:'<td id="ssa" width="2px" class="odd-column">']}"""
print(string)
sstring = re.sub(r'\"','\\"',string)
print(sstring)
the output is
{['abc.abc',\"dsa\",asd:'<td id=\"ssa\" width=\"2px\" class=\"odd-column\">']}
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 7 years ago.
Improve this question
Here is what I currently have, which is not working:
if "Forwarder" not in shp_name or "T_" not in shp_name or "Grad" not in shp_name:
I've also tried:
if ("Forwarder", "T_", "Grad") not in shp_name:
Samples of the input would be "DS_Forwarder_1" or "DS_Harvester_1". The script proceeds directly to else as it's unable to identify any of the above substrings in the primary string.
Try using the any built in.
if any(s in shp_name for s in ("Forwarder", "T_", "Grad")):
...
This will be true if any of the given strings are present in shp_name. You can use if not any(... if you want False when one of the strings is present.
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 7 years ago.
Improve this question
What is the fastes way to convert a string to float if it doesn has a standard format?
In my special case I need to read these strings and convert them to float
-7.5-4
7.5-5
that correspond to the numbers -7.5E-4 and 7.5E-5
I need the fastest because I'm loading big size files.
Thanks
This lambda works with your test cases (also with a leading '+'):
to_num = lambda s: (1,-1)[s[0]=='-']*
float(s.lstrip('-+').replace('-','E-').replace('+','E+'))
The opening (1,-1)[s[0]=='-'] takes care of multiplying by -1 if there is a leading '-', then the float conversion strips leading '+' and '-' signs, and replaces embedded '+' and '-' with 'E+' and 'E-', permitting a valid conversion to float.
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 8 years ago.
Improve this question
I have a huge text file, each line has a tab-delimited string. I need to keep all tabs apart from those at the end of each line. I need to keep the carriage return. Any ideas?
I've tried everything on these answers:
How to trim whitespace (including tabs)?
Trimming a string in Python
Strip spaces/tabs/newlines - python
as well as others I've now closed the tabs on.
Just use a regular expression
>>> import re
>>> s="1\t2\t3\t\t\n"
>>> s2=re.sub('\t+\n','\n',s)
>>> s2
'1\t2\t3\n'