I have a (very ugly) txt output from an SQL query which is performed by external system that I can't change. Here is the output example:
FruitName Owner OwnerPhone
============= ================= ============
Red Apple Sr Lorem Ipsum 123123
Yellow Banana Ms Dolor sir Amet 456456
As you can see, the FruitName
column and the Owner
column may consists of few words and there's no fixed pattern in how many words could be in these columns. If I use line.split()
to make array on each line Python, it will remove all the whitespace and make the array become like this:
['Red', 'Apple', 'Sr', 'Lorem', 'Ipsum', '123123']
['Yellow', 'Banana', 'Ms', 'Dolor', 'sir', 'Amet', '456456']
The question is, how can I split it properly into output like this:
['Red Apple', 'Sr Lorem Ipsum', '123123']
['Yellow Banana', 'Ms Dolor sir Amet', '456456']
I'm a newbie in Python and I dont know if such thing is possible or not. Any help will be very much appreciated. Thanks!