Skip to content Skip to sidebar Skip to footer

Pulling Parts From A String (python)

I have a file with strings like the following: NM_???? chr12 - 10 110 10 110 3 10,50,100, 20,60,110, I am interested in the last two columns, the first being a comma-separeted lis

Solution 1:

I think the most Pythonic way to say that is:

''.join(chr_string[a[0]:a[1]] for a in myList)

Solution 2:

"".join(chr_string[slice(*exon_interval)] for exon_interval in zipped)

Solution 3:

To get a list by slicing chr_string (which I have fabricated) using these pairs:

>>> [chr_string[start:end + 1] for start,end in zip(exonstarts, exonends)]
['05060708091', '25262728293', '50515253545']

To join these together:

>>>''.join(chr_string[start:end+1] forstart,endin zip(exonstarts, exonends))
'050607080912526272829350515253545'

Post a Comment for "Pulling Parts From A String (python)"