# List Comprehension gurus

**URL:** <https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395>\
**Category:** Ignition\
**Created:** [October 25, 2019, 1:20pm UTC](https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395 "2019-10-25T13:20:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [October 25, 2019, 1:20pm UTC](https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395/1 "2019-10-25T13:20:18Z")

</div>

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.

```auto
xDS=['Col1','Col2','Col3','Col4','a_b_c_d_e_f_g_h_i_j_k_l_m','Col6','Col7']
ResultDS=['Col1','Col2','Col3','Col4','a_b_c_d_e_f_g_h_i_j_k_l_m','Col6','Col7','Col8','Col9','Col10','Col11','Col12','Col13','Col14','Col15','Col16','Col17','Col18','Col19','Col20']

```

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

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 25, 2019, 1:28pm UTC](https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395/2 "2019-10-25T13:28:08Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 25, 2019, 1:31pm UTC](https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395/3 "2019-10-25T13:31:59Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [October 28, 2019, 9:29pm UTC](https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395/4 "2019-10-28T21:29:24Z")

</div>

@pturmel, do you ever sleep?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 29, 2019, 5:45pm UTC](https://forum.inductiveautomation.com/t/list-comprehension-gurus/29395/5 "2019-10-29T17:45:54Z")

</div>

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