# Python List Comprehensions Help

**URL:** <https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621>\
**Category:** Ignition\
**Created:** [February 28, 2022, 3:12pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621 "2022-02-28T15:12:54Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 11, 2022, 8:53pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/61 "2022-03-11T20:53:03Z")

</div>

> [@zacharyw.larson](#):
>
> When I see a dictionary, I think of it as a future relatively unchanging table that will make for using in queries. Or are dictionaries more optimal than queries in that application?

I wouldn't try to equate a dictionary to any more than it is.

A tool. That tool happens to be **An unordered set of key value pairs**. How and when you use that tool is up to you.

Just like List Comprehensions are a tool you can use, sometimes they are not the best tool to use, sometimes its a matter of preference. Either way it's good to know how to use the tool when you need it.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2022, 9:36pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/62 "2022-03-11T21:36:46Z")

</div>

```auto
thisList=[]

#sum the data
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
	if type(valuesSticks) == int:
		thisList.append(valueShift+valueDaily)

valuesSticks
valuesDailySticks
thisList

```

output:

```auto
[14850, 23370, 23166, None, 18449, 35670, 0, 24741, 24600, 0, 0, 0, 0, None, 30075, 0, 20744]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[]

```

I don’t understand why this is not working.

```auto
thisList=[]

#sum the data
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
	if type(valuesSticks) != (str or NoneType):
		thisList.append(valueShift+valueDaily)
	else :
		thisList.append(valueDaily)

valuesSticks
valuesDailySticks
thisList

```

```auto

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

```

I need them to line up.  
I guess I can’t zip them or something if one has none type.

update  
seems I can zip, but I can’t for loop them

So if I can list comprehension them instead, that might work?  
I don’t know how to write this kind of list comprehension though

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 11, 2022, 9:52pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/63 "2022-03-11T21:52:18Z")

</div>

If you want to check the type of something, don’t use `type()` instead use `isinstance()`.

```auto

thisList=[]

#sum the data
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
	if isinstance(valueShift,int): 
		thisList.append(valueShift+valueDaily)

valuesSticks
valuesDailySticks
thisList

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 11, 2022, 10:00pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/64 "2022-03-11T22:00:37Z")

</div>

still didnt work

```auto
thisList=[]

#sum the data
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
	if isinstance(valuesSticks,int):
		thisList.append(valueShift+valueDaily)
	else :
		thisList.append(valueDaily)

valuesSticks
valuesDailySticks
thisList

```

output

```auto
[21600, 30750, 29484, None, 26763, 47970, 0, 35649, 29520, 0, 0, 0, 0, None, 32832, 0, 28400]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

```

I need to say like is not none maybe

or I have to pre-process the quality, generate a list of numbers of which ones are not good, then use that to construct the other list  
Then my list would be so dynamic though, and I am not sure if I can line it up.  
I will have to look at it on Monday, must be simpler.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 11, 2022, 11:47pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/65 "2022-03-11T23:47:32Z")

</div>

At a glance `valuesSticks` isn’t an integer, from the name I’m guessing it’s a list, which means you’re falling through and always executing `thisList.append(valueDaily)` which may well always be zero.

To my eye the code did exactly what it is expected.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 12, 2022, 8:13am UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/66 "2022-03-12T08:13:26Z")

</div>

If you’re exploring python, then I have suggestions. There are many ways of doing things, so here are some, try them out, mix them up, and figure out what you prefer.

tuples are cool and easy to unpack, which can be useful with iterations:

```python
machines = [
    ('S', [2,4,5,7,8,9,10,11,12]),
    ('A', [3,6,14,15,16,17,18])
]
base_tagpath = '[Test]M{0:02d}/M{0:02d}ProductionData/M{0:02d}{1}'
tagpaths = [base_tagpath.format(num, counter_type) for counter_type, nums in machines for num in nums]

base_snappath = '[Test]M{0:02d}/M{0:02d}ProductionData/Sticks Snapshot'
snappaths = [base_snappath.format(num) for _, nums in machines for num in nums]

```

dicts are also very cool and offer a neat way to group data. Lists of dicts are also cool.  
Also, nesting comprehensions is not super intuitive at first but makes for a very concise way of looping through nested data structures:

```python
paths = [
    {
        'tag': base_tagpath.format(num, counter_type),
        'snap': base_snappath.format(num)
    } for counter_type, nums in machines for num in nums
]

```

You can nest things until you get nauseous (don’t do this):

```python
data = [
    {
        'value': tag.value,
        'snap': base_snappath.format(num)
    } for tag, num in zip(
        system.tag.readBlocking([base_tagpath.format(num, counter_type) for counter_type, nums in machines for num in nums]),
        (num for _, nums in machines for num in nums)
    )
]

```

And while we’re in a comprehension thread:

```python
thisList = [vshift + vdaily if isinstance(vshift, int) else vdaily for vshift, vdaily in zip(sticks, daily_sticks)]

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 14, 2022, 1:55pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/67 "2022-03-14T13:55:16Z")

</div>

**How do you produce a list of the ‘i’ values that had good tags?**

I can get the tag paths or values like this:

```auto
if 'Good' in str(qValue.quality):
		tagsOut.append(tag)

```

how would I get a list like these machines have good tags:

```auto
goodTagMachines=[1,2,4,5,8,9]

```

So I can use the list to get the machines and to designate which machines I am writing.  
Struggling with trying to reference ‘i’ value inside the list comprehension.  
I don’t see examples of it on the pages of instructions that I check.

* * *

**I am struggling when a list has a Nonetype.**

the old script had lines for each machine  
if one errored for nonetype, then that machine’s lines were commented out with `#`):

```auto
#script starts with reading a bunch of values to a bunch of variables like this
M1Net=system.tag.read("[Test]department/products/M01/M01_Production/M01Net A Counter")

#at a certain time, if statement, a shift ends and a rolling total is captured for many machines
system.tag.writeBlocking(["[Test]department/products/M01/combined shifts/Net"],[system.tag.read("[Test]department/products/M01/combined shifts/Net").value+M1Net.value])

```

So I tried things like this that threw errors for type error unsupported none:

```auto
numMachines = 18
exceptions =[2,4,5,7,8,9,10,11,12]
nonExceptions = [1,3,6,14,15,16,17,18]

# at the specified time in an If statement
baseNetPaths='[Test]department/products/M{0:02d}/M{0:02d}_Production/{0:02d}Net{counter}
pathsNet=([baseNetPaths.format(i,counter=' S Counter') for i in exceptions]+
          [baseNetPaths.format(i,counter=' A Counter') for i in nonExceptons])

valueSticks=[tag.value for tag in system.tag.readBlocking(pathsNet)]

baseNetDailyPaths = '[Test]department/products/M{0:02d}/combined shifts/Net'
pathsNetDaily =( [baseNetDailyPaths.format(i) for i in exceptions]+
                 [baseNetDailyPaths.format(i) for i in nonExceptions])

valuesDailySticks =[tag.value for tag in system.tag.readBlocking(pathNetDaily)]
valuesDailySticks

thisList=[]

#sum the data
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
	if valuesSticks!='NoneType':
		thisList.append(valueShift+valueDaily)
	else :
		thisList.append(valueDaily)

valuesSticks
valuesDailySticks
thisList

```

and it just threw errors because of nonetypes

So I think either I need to get a list of the good ‘i’ values, or I need to find a way to eliminate the nonetype error

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [March 14, 2022, 2:02pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/68 "2022-03-14T14:02:33Z")

</div>

> [@zacharyw.larson](#):
>
> Struggling with trying to reference ‘i’ value inside the list comprehension.

`enumerate`.

```python
goodMachines = [i for i, qval in enumerate(system.tag.readBlocking(paths)) if qval.quality.isGood()]

```

or, checking for None instead of qualities:

```python
[i for i, thing in enumerate(things) if thing is not None]

```

But depending on what you're trying to do, matching paths with values in a dictionary as I described in a previous posts might be more useful.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 14, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/69 "2022-03-14T14:28:52Z")

</div>

> [@zacharyw.larson](#):
>
> ```auto
> if type(valuesSticks) != (str or NoneType):
> thisList.append(valueShift+valueDaily)
> else :
> thisList.append(valueDaily)
> 
> ```

This type of logic doesn't work, or at the very lest it doesn't work the way you expect it to.

If you were truly wanting to write this as a conditional statement, what I think you were trying to do is this:

```auto
if type(valueSsticks) != str or type(valuesSticks) != NoneType:

```

However, as discussed use `isinstance` to check for the type of an object. Or in the case of NoneType you can just check that the variable is not None

> [@zacharyw.larson](#):
>
> ```auto
> for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
> if valuesSticks!='NoneType':
> thisList.append(valueShift+valueDaily)
> else :
> thisList.append(valueDaily)
> 
> ```

Should Be:

```auto
for valueShift,valueDaily in zip(valueSticks,valuesDailySticks):
    if valuesSticks: #Logically equivilent to if valuesSticks is not None
       thisList.append(valueShift + valueDaily)
    else:
       thisList.append(valueDaily)

```

Or since this is a thread about comprehensions this can be written as one as well:

```python
thisList = [valueShift + valueDaily if valuesSticks else valueDaily for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks)]

```

To explain the syntax here, it takes advantage of inline if statements. Anytime you have a structure like:

```auto
if condition:
    thisVar = someThing
else:
   thisVar = someOtherThing

```

you can write it like this:

```python
thisVar = something if condition else someOtherThing

```

So that will condence your for loop to this:

```python
for valueShift, valueDaily in zip(valuesSticks,valuesDailySticks):
    thisList.append(valueShift + valueDaily if valuesSticks else valueDaily)

```

Which can be written as the comprehension above.

Another note, as has been stated already, be careful of your naming. `valueShift` and `valuesSticks` are very similar and pretty easy to transpose.

This:

```python
for valueShift, valueDaily in zip(valuesSticks,valuesDailySticks):
    if valueShift:
        thisList.append(valueShift + valueDaily)
    else:
        thisList.append(valueDaily)

```

Is very different from what you have.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 14, 2022, 2:30pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/70 "2022-03-14T14:30:59Z")

</div>

```auto
Traceback (most recent call last):
  File "<input>", line 42, in <module>
TypeError: unsupported operand type(s) for +: 'com.inductiveautomation.ignition.common.model.values.BasicQualifiedValue' and 'int'

```

for

```auto

#sum the data
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
	if valuesSticks :
		thisList.append(valueShift+valueDaily)
	else :
		thisList.append(valueDaily)

valuesSticks
valuesDailySticks
thisList

```

line 42 is where it is appending the addition

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 14, 2022, 2:33pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/71 "2022-03-14T14:33:17Z")

</div>

Read my full post:

valuesSticks is a list, which could contain NoneType objects, but not be None itself.

valueShift is a member of that list.

```python
for valueShift,valueDaily in zip(valuesSticks,valuesDailySticks):
    if valueShift:
        thisList.append(valueShift + valueDaily)
    else:
        thisList.append(valueDaily)

valuesSticks
valuesDailySticks
thisList

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2022, 2:34pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/72 "2022-03-14T14:34:12Z")

</div>

using an ‘or’ can help with a null value:

```python
list1 = [1,2,3,None,5]
list2 = [1,2,None,4,5]

sumList = [(a or 0) + (b or 0) for a, b in zip(list1, list2)]

print sumList

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/2/72a7d41af0ab488a42b38da3ed4623495cbf858c.png)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 14, 2022, 2:49pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/73 "2022-03-14T14:49:41Z")

</div>

I messed up the valueShift and valuesSticks mixing up for sure

Thanks

That is amazing Jordan  
Tried:

```auto
print valuesSticks
print valuesDailySticks
sumList = [(a or 0)+(b or 0) for a,b in zip(valuesSticks,valuesDailySticks)]
print sumList

```

output

```auto
[0, 30750, 50544, None, 83212, 50430, 0, 52615, 0, 0, 0, 0, 0, None, 68241, 0, 73622]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 30750, 50544, 0, 83212, 50430, 0, 52615, 0, 0, 0, 0, 0, 0, 68241, 0, 73622]

```

The ordering is preserved.  
I don’t have to use enumerate to see the indexes of good and try to correlate them across the two lists of counters.

It is just like

base Path  
Paths from list comprehension to get all the machines  
list comprehension to read the values

repeat that for the daily

then just add them with the or

now I can write them with a list comprehension easy too

* * *

revised

```auto

print valuesSticks
print valuesDailySticks
sumList = [(a or 0)+(b or 0) for a,b in zip(valuesSticks,valuesDailySticks)]
print sumList

thisList=[]
for a,b in zip(valuesSticks,valuesDailySticks):
    if a:
        thisList.append(valueShift + valueDaily)
    else:
        thisList.append(valueDaily)
print 'here'
valuesSticks
valuesDailySticks
thisList

```

```auto
[0, 34440, 52650, None, 85227, 52890, 0, 55817, 0, 0, 0, 0, 0, None, 70575, 0, 76626]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 34440, 52650, 0, 85227, 52890, 0, 55817, 0, 0, 0, 0, 0, 0, 70575, 0, 76626]
here
[0, 34440, 52650, None, 85227, 52890, 0, 55817, 0, 0, 0, 0, 0, None, 70575, 0, 76626]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 75595, 75595, 0, 75595, 75595, 0, 75595, 0, 0, 0, 0, 0, 0, 75595, 0, 75595]

```

oh I see it, I needed to reinitialize `thisList =[]`

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 14, 2022, 3:01pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/74 "2022-03-14T15:01:53Z")

</div>

You changed your loop variables but still used the old names in your loop.

```auto
for a,b in zip(valuesSticks,valuesDailySticks):
   if a:
       thisList.append(a + b)
   else:
       thisList.append(b)

```

Careful. Try to use meaningful names in code. Not only does it provide some documentation but it makes it easier to follow what is going on.

Perhaps:

```python
for shiftSticks, dailySticks in zip(valuesSticks,valuesDailySticks):
    if shiftSticks:
        thisList.append(shiftSticks + dailySticks)
    else:
        thisList.append(dailySticks)

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 14, 2022, 3:04pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/75 "2022-03-14T15:04:39Z")

</div>

I don’t understand how it worked with the old variables in there

oh, it kind of was stored in memory huh?

so if I closed the script console, then reopened it, then that would have thrown an error?

* * *

I appreciate the reminders to use relevant naming. I intend to.  
Kind of scrambling to keep up with reading about things suggested, testing them, and trying new things.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2022, 3:34pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/76 "2022-03-14T15:34:06Z")

</div>

> [@zacharyw.larson](#):
>
> oh, it kind of was stored in memory huh?

Yep. Even if you close it and reopen it in the same session. Using the reset button helps alleviate that.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/4/d443cca087351535a31121b830c76d0d0d0b7b9f.png)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 14, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/77 "2022-03-14T17:18:56Z")

</div>

I used len() to get the length of a list I have

it is 71 elements long

I want to test system.tag.writeBlocking()  
What is the best way to write a tag that be written to in this way?

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/96ce4b8a18acfeb9ef58d70931f68c6239b06065.png)

Do I just make an array type memory tag and write to it?

[https://docs.inductiveautomation.com/display/DOC81/Tag+Data+Types#TagDataTypes-ArrayTags](https://docs.inductiveautomation.com/display/DOC81/Tag+Data+Types#TagDataTypes-ArrayTags)

I don’t see if I can do this. I will try.

* * *

was odd

```auto
system.tag.writeBlocking(testPath,valuesShift)
print system.tag.readBlocking(testPath)

```

```auto
[0, 0, 0, 83352, 96878, 0, None, 134915, ......]
71
[Good]
[[[Ljava.lang.Long;@*******, Good, Mon Mar 14 13:25:00 EDT 2022 (**********)]]

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2022, 5:38pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/78 "2022-03-14T17:38:33Z")

</div>

As you already saw, I don’t use arrays much. 😉

To a dataset tag. This can let you see all the values a once.  
EDIT: Technically, you could just use a single column, but the idx column gives a visual reference.

```python
datasetOut = system.dataset.toDataSet(['idx', 'values'], [[i, value] for i, value in enumerate(listOfValues)])
system.tag.writeBlocking(['[provder]path/to/tag'], [datasetOut])

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [March 14, 2022, 5:45pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/79 "2022-03-14T17:45:04Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/b/bbf5a3feb95b7c76b4fb7d0d4b92849d4d11a5a4.png)

Thanks

that worked great

the none value was “written” without an error

I was only a little concerned, but it is so nice to have a peaceful mind.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [March 14, 2022, 5:46pm UTC](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621/80 "2022-03-14T17:46:13Z")

</div>

> [@zacharyw.larson](#):
>
> it is so nice to have a peaceful mind

For me, that ship has sailed. lol

[Previous page](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621.md?page=3)

[Next page](https://forum.inductiveautomation.com/t/python-list-comprehensions-help/56621.md?page=5)
