We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
Probably a typo...the author should correct the words to words2
how can i split a continous string 'AGGCATGCATGCAT' into triplets --> 'AGG', 'CAT'.... etc, you get the point, ? please
>>> s = 'AGGCATGCATGCAT'
>>> s[0:3]
'AGG'
>>> [s[i:i+3] for i in range(0,len(s),3)]
['AGG', 'CAT', 'GCA', 'TGC', 'AT']
Thank you very much! You're awesome! Yeah, I'm making proteins, too. :D
why protein make dna that will make proteins instead ......LOL
use bioperl instead ....Splice function
simply awesome
a = 'sdfgjrerdfsfgdfg'
q = []
for x in range(0, len(a), 3):
z = (a[x:x+3])
q = q + [z]
print(q)
>>>
['sdf', 'gjr', 'erd', 'fsf', 'gdf', 'g']
Are you making proteins? :-D
correctness and clarity should be the main goal of a post. well nice info about pyrhon programming
Did you mean to say:
words2 = words.split(" ")
instead of:
words2 = word.split(" ")
That's such a minor error - I don't think anyone would've mind it being there xD
Thanks for the catch! We have corrected.
What if there's an excess amount of white space between words? how do we use strip to work with split?
str.split() with no arguments strips away all the whitespace.
i have a question.. how do you get a data from a text file that is put this way (a txt file of a coordinate) :
6,8 2,6
2,6 3,0
6,4 7,8
6,4 4,3
3,0 4,3
and output it so that in an array it shows only one of each coordinates.. its really hard for me.
But how can I split from commas and newlines at the same time if I read from file: "Names.txt".
For Example:
Thomas, Julie
Rick
Emma, Sam
John, Anna
to: ['Thomas', 'Julie', 'Rick', 'Emma', 'Sam', 'John', 'Anna']
So you don't have to add a separate 'print' line when calling the '.split()' command? Print is built in to the command?
if I have a list like ..x = [1,2.5,'A', 'R', 23, 55.5] how can I get l_1 = [1,2,23], l_2 =[2.5,55], s_t = [A,R]
use the power of Python!!!!
i_1 = [y for y in x if type(y) == int]
i_2 = [y for y in x if type(y) == float]
s_t = [y for y in x if type(y) == str]
yes, it is that simple. This is three lines with no "side effects".
x = [1,2.5,'A', 'R', 23, 55.5]
i=0
l_1=[]
l_2=[]
s_t=[]
y=[]
while i<len(x): if="" type(x[i])="=" int:="" l_1.append(x[i])="" elif="" type(x[i])="=" float:="" l_2.append(x[i])="" elif="" type(x[i])="=" str:="" s_t.append(x[i])="" else:="" print="" x[i],'not="" defined="" '="" y.append()="" i+="1">
If I only had a penny for every time someone did not use a comprehension and should have... I would be a thousandaire. Python is a powerful and compact language. If you find your code overly long and complex, review it, I guarantee there is a better way to utilize Python's capabilities. I am no expert by any means, but I do believe in improving what needs improvement.
how can I split a sting into a list by every upper letter in the way for example str_list = [“This”, “is”, “not a Red”, “”, “wine, but a white One”] it will give us split_str_list = [“This”, “is”, “not a ”, ”Red”, “”, “wine, but a white “, ”One”]
import sys
def BreakOnUpper(str_list):
newstr = []
for i,e in enumerate(str_list):
if any(c.isupper()for c in e): # is there an uppercase letter in e?
for p,c in enumerate(e): #at what position?
if c.isupper():
if i>1:
newstr.append(e[:p])
newstr.append(e[p:])
break
else: #just append anything that does not contain an uppercase letter
newstr.append(e)
return newstr
def main():
str_list = ["This", "is", "not a Red", "", "wine, but a white One"]
print(BreakOnUpper(str_list))
if __name__ == "__main__":
sys.exit(main())
isnt this also a typo?
>>> a,b,c = x.split(“,”)
isn't this supposed to be:
>>> (a,b,c) = x.split(“,”)
No it is not, a,b,c will also work
hello how can i split on non alphabetic characters i used split([^a-zA-Z]) and did not work
Look up their unicode equivalent (UTC-8)
I am very greatful to you guys for this explanation. thank you.
What an awesome resource.
Thanks. Helped me.
The ( ' This is some random text ' ) problem has some issues. I use ie10 and the first var is ( word), the second var is (words2) and the third is (words). The problem works with one var , (word). It will not work the way it is written.