List Comprehension gurus

Ok gurus here is something I think can be shrunk down.
We have an XML file that we take and using xmltodict turn it into a dataset.
We end up with 50 rows of data and 7 columns.
Column 5 in the dataset contains a string that we parse using .split(’_’) that splits into 13 values.
What I need to do is loop the DS, parse col 5, take the 13 values from col 5, and then combine those values to the end of that record.
Write the DS to a Dataset tag.

Basically take xDS turn it into a pyDataSet, loop it, parsing col 5, take 13 values from col5, put them on the end of the record.


Impress me list comprehension gurus.
I can do it, but the old man way lol

newRows = [[x for x in row]+row[4].split('_') for row in system.dataset.toPyDataset(xDS)]

If the split won’t always yield thirteen values, you can use this:

newRows = [[x for x in row]+(row[4].split('_')+[None]*13)[:13] for row in system.dataset.toPyDataset(xDS)]

@pturmel, do you ever sleep?


I travel a lot. Ya never know what time zone I’ll be in. /:

1 Like