Skip to content
Advertisement

Parsing line with delimiter in Python

I have lines of data which I want to parse. The data looks like this:

JavaScript

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:

JavaScript

Please advice what’s the right way to do it?

Advertisement

Answer

It looks like you want to split each line up by spaces, and parse each chunk separately. If mafLines is a string (ie. one line from .readlines():

JavaScript

The way you were doing it would iterate over each character in the first line (since it’s a list of strings) rather than on each space.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement