This question already has answers here:
How to replace two things at once in a string?
(6 answers)
using .replace to replace more than one character in python [duplicate]
(4 answers)
Closed 2 years ago.
I have a question regarding my code below:
Input: A DNA string Pattern (ex: 'AAAACCCGGT')
Output: The complementary string (ex: 'TTTTGGGCCA')
def Complement(Pattern):
comPattern=Pattern.translate(str.maketrans({'A':'T','T':'A','G':'C','C':'G'}))
return comPattern
I tried using str.replace() method multiple times for above problem, but it did not work. Any idea why?
Related
This question already has answers here:
Reuse part of a Regex pattern
(6 answers)
Is it possible to define a pattern and reuse it to capture multiple groups?
(1 answer)
Closed 2 years ago.
I'm trying to match strings of the form:
"FLOAT:FLOAT:FLOAT"
where:
FLOAT="(\d*\.\d*)"
I would like to not repeat code. (eg. "(\d*\.\d*):(\d*\.\d*):(\d*\.\d*)")
Is there support for this in regex? Or is this typically done with string manipulation (.format())?
I'm using python, but I'm interested in other flavors of regex as well.
This question already has answers here:
Python format throws KeyError
(1 answer)
How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?
(23 answers)
Closed 3 years ago.
I just want the following outcome.
But I get KeyError: '"msg_body"'.
input:
text="text"
uid="uid"
input = '{"msg_body":{input_text}, "user_id":{input_uid}}'.format(input_text=text, input_uid=test)
wanted output:
'{"msg_body":"text", "user_id":"uid"}'
Single or double quotations must be exactly how it is above.
Thanks
This question already has answers here:
List of all unique characters in a string?
(9 answers)
Count the number of unique characters in a string using only for loops and if/else operations [duplicate]
(5 answers)
Closed 5 years ago.
im making a script in python, and i want to know how to count the types of letters in a string. For example, if my string is abcc, it should return 3. because theres a, b, and c. if its accc, it should return 2. if its abcdeff it should return 6. So, how do i do this?
This question already has answers here:
How do I reverse a string in Python?
(19 answers)
Closed 5 years ago.
I have a string:
ahdeg
What is the best way to reverse a string in python so it would be:
gedha
Anything would help, thanks!
Say you have a string.
string = 'Test'
string[::-1] would reverse this into 'tseT'
This question already has answers here:
What's the u prefix in a Python string?
(5 answers)
Closed 6 years ago.
I am trying to parse the 'Meghan' part from the line:
link = http://python-data.dr-chuck.net/known_by_Meghan.html
...with the following regex:
print re.findall('by_(\S+).html$',link)
I am getting the output:
[u'Meghan']
Why I am getting the 'u'?
It means unicode. Depending on what you'll do with it, you can ignore it for the most part, of you can convert it to ascii by doing .encode('ascii')