This question already has answers here:
Generate a random letter in Python
(23 answers)
Closed 5 years ago.
In python I want to know how to get random letter from string.
eg.
randomize("HELLO")
returns "L"
return (random.choice(string))
Related
This question already has answers here:
How to get the size of a string in Python?
(6 answers)
Closed 1 year ago.
This is what have tried but it's not working
lens("Father")
it's len('Father') not lens('Father')
len(Father)
Your mistake is the 's' at the end of len's'
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 to print without a newline or space
(26 answers)
Closed 5 years ago.
I have this code but i would like the numbers to be printed next to one another but it doesn't do that it just prints down the screen instead of filling up the screen.
import random
count=2
while count>0:
print(random.randint(0,1))
replace
print(random.randint(0,1))
with
print(random.randint(0,1), end="").
See https://docs.python.org/3/tutorial/inputoutput.html
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'