This question already has answers here:
How do I do a case-insensitive string comparison?
(15 answers)
Closed 8 years ago.
For example i am given this string as an input:
"HeLlo"
How can i make this case insensitive for later uses?
I want it to be equal to "hello" or "HELLo" etc...
You have the "your string".upper() or "your string".lower() functions, which will allow you to compare the strings, assuring the comparison is case insensitive.
Related
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?
This question already has answers here:
How do I do a case-insensitive string comparison?
(15 answers)
Closed 3 years ago.
I am trying to compare two string and ignore case- sensitive but i don't want to use .lower() or .upper(). Is there another way of doing this?
example1 = "hello"
example2 = "HeLlo"
if example1.casefold()==example2.casefold():
#do something
This will work without needing upper() or lower(). Might not work for non-ASCII characters.
This question already has answers here:
Check if multiple strings exist in another string
(17 answers)
Closed 3 years ago.
if "a_string" in random_word or "b_string" in random_word:
...
Is there a cleaner, less dense way to write this boolean?
In case of if, you could use any to check for the occurrence of either of the two strings
if any(i in random_word for i in ["a_string", "b_string"]):
You can use a regular expression.
import re
if re.search(r'a_string|b_string', random_word):
...
This question already has answers here:
Checking whether a string starts with XXXX
(5 answers)
Closed 5 years ago.
To detect whether a python string ends with a particular substring, say ".txt", there is a convenient built-in python string method;
if file_string.endswith(".txt"):
I would like to to detect whether a python string begins with a particular substring, say "begin_like_this". I am not able find a convenient method that I can use like this;
if file_string.beginswith("begin_like_this"):
I am using Python 3.6.
You're looking for str.startswith
if file_string.startswith("begin_like_this"):
This question already has answers here:
Is there a way to convert number words to Integers?
(17 answers)
Closed 5 years ago.
What is the best way to parse non-digit strings e.g. "twenty two"->22 to integer or double values in python ? Especially what is the best way to detect that region if there are additional words in a sentence.
Thanks
https://github.com/akshaynagpal/w2n this has pip install
Original Comment here
https://stackoverflow.com/a/34569447