Parsing line with delimiter in Python
Posted
by neversaint
on Stack Overflow
See other posts from Stack Overflow
or by neversaint
Published on 2010-06-02T01:25:15Z
Indexed on
2010/06/02
1:33 UTC
Read the original article
Hit count: 215
I have lines of data which I want to parse. The data looks like this:
a score=216 expect=1.05e-06
a score=180 expect=0.0394
What I want to do is to have a subroutine that parse them and return 2 values (score and expect) for each line.
However this function of mine doesn't seem to work:
def scoreEvalFromMaf(mafLines):
for word in mafLines[0]:
if word.startswith("score="):
theScore = word.split('=')[1]
theEval = word.split('=')[2]
return [theScore, theEval]
raise Exception("encountered an alignment without a score")
Please advice what's the right way to do it?
© Stack Overflow or respective owner