# List to dataset

**URL:** <https://forum.inductiveautomation.com/t/list-to-dataset/10166>\
**Category:** Ignition\
**Created:** [June 23, 2015, 9:45pm UTC](https://forum.inductiveautomation.com/t/list-to-dataset/10166 "2015-06-23T21:45:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [June 23, 2015, 9:45pm UTC](https://forum.inductiveautomation.com/t/list-to-dataset/10166/1 "2015-06-23T21:45:53Z")

</div>

I have some code which takes a text file and calculates the index weight of each row and counts the number of duplicates. I would like to get the results into a dataset I can bind to a table component, but am not sure how to make the conversion.

[code]path = system.file.openFile(“txt”)

if path != None:  
contents = system.file.readFileAsString(path).splitlines()

l=[]

for line in contents:  
v0 = (len(line[0:20]) - len(line[0:20].lstrip()))/2  
v1 = line[0:30].replace("\*","").strip()  
v2 = contents.count(line[0:30])  
v3 = ‘’

```
l.extend([v0,v1,v2, v3])

```

for each in l:  
print each[/code]  
Output:

[code]0  
O “Alternate Hierarchies”  
1

1  
“WC BOM”  
1

2  
“A2160”  
1

3  
“etn110444”  
1

4  
“03m7185”  
2

4  
“03m7185”  
2

4  
“14m7396”  
2

4  
“14m7396”  
2  
[/code]

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [June 24, 2015, 12:08am UTC](https://forum.inductiveautomation.com/t/list-to-dataset/10166/2 "2015-06-24T00:08:02Z")

</div>

Hi Tim,

Do something like this:

```auto
path = system.file.openFile("txt")
   
if path != None:
   contents = system.file.readFileAsString(path).splitlines()

l=[]

for line in contents:
   v0 = (len(line[0:20]) - len(line[0:20].lstrip()))/2
   v1 = line[0:30].replace("*","").strip()
   v2 = contents.count(line[0:30])
   v3 = ''
   l.append([v0,v1,v2,v3])

table = event.source.parent.getComponent("Table")
columns = ["FirstCol","SecondCol","ThirdCol","FourthCol"]
table.data = system.dataset.toDataSet(columns,l)
```

Best,

---

<div class="post-metadata">

**Author:** ![Tim](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tim/32/3361_2.png) [@Tim](https://forum.inductiveautomation.com/u/Tim)\
**Post date:** [June 24, 2015, 12:54pm UTC](https://forum.inductiveautomation.com/t/list-to-dataset/10166/3 "2015-06-24T12:54:37Z")

</div>

Thanks Nick
