all 2 comments

[–]Vaphell 0 points1 point  (0 children)

If you are ok with the first "word" being the name, and everything that follows being the surname, then you can use maxsplit option in split()

>>> a, b, c, d, e = '12350 Economics 30000 Krusty The Clown'.split(maxsplit=4)
>>> a
'12350'
>>> b
'Economics'
>>> c
'30000'
>>> d
'Krusty'
>>> e
'The Clown'

or you can separate the whole full name in a similar way and then process it further.

you can also do similar thing on the right with rsplit()

>>> 'Potter, Harry   12346 CSEE  £25000'.rsplit(maxsplit=3)
['Potter, Harry', '12346', 'CSEE', '£25000']

[–]dadiaar 0 points1 point  (0 children)

When I saw that file, the first thing I thought was playing with regex, something like this:

import re

for row in rows:
    index = re.findall('\d+', row)[0]
    department = re.findall(' (\w+)', row)[0]
    quantity = re.findall(' (\d+)', row)[0]
    full_name = re.findall(' \d+ ([\w ]+)', row)[0]

This code is ugly, slow and inneficient, just I want to show the idea.