3

What i want to do is split a line such as >m27348020>m8918930 into a list in this format ['>m27348020', '>m8911830]

Is there any way to do this using re.split? The split would happen at the > symbol.

Jbund
  • 29
  • 2

2 Answers2

2

Instead of split you can easily do

import re
x=">m27348020>m8918930"
print re.findall(r">[^>]*",x)
vks
  • 67,027
  • 10
  • 91
  • 124
1

You may simply split the string on the given separator and then simply concatenate the separator at the start of each split element.

separator = ">"

line = ">m27348020>m8918930"

print [separator+i for i in line.split(separator) if len(i)>0]

>>> ['>m27348020', '>m8918930']
ZdaR
  • 22,343
  • 7
  • 66
  • 87