# Quantify labels with Names in them

**URL:** <https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [March 27, 2023, 3:10pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646 "2023-03-27T15:10:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 3:10pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/1 "2023-03-27T15:10:17Z")

</div>

Is there a way for me to take tags/components that have names in them and quantify them? In the pic below youll see that Jerome Smith appears in 5 areas, how do I make that into a memory tag that tells me that?

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

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 27, 2023, 3:24pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/2 "2023-03-27T15:24:34Z")

</div>

Where are the names in the labels coming from? Are they tag bindings, or what?

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 3:25pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/3 "2023-03-27T15:25:50Z")

</div>

They are tag bindings

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [March 27, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/4 "2023-03-27T15:29:51Z")

</div>

Sounds like you would write a script to read all your tags and loop over the results to create a list of duplicate values.

```auto
a = [1,2,3,2,1,5,6,5,5,5]

import collections
print([item for item, count in collections.Counter(a).items() if count > 1])

> [1, 2, 5]

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 3:39pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/5 "2023-03-27T15:39:14Z")

</div>

Looks like a start, thanks

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 4:17pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/6 "2023-03-27T16:17:21Z")

</div>

So, I have this, which is a start

```auto
names = [
	system.tag.readBlocking("[default]Phase 1 Extrusion/L31/L31_Pos1/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L31/L31_Pos2/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L31/L31_Pos3/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L31/L31_Pos4/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L11/L11_Pos1/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L11/L11_Pos1/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L11/L11_Pos2/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L11/L11_Pos3/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L11/L11_Pos4/Assigned Operator Name")[0].value,
	system.tag.readBlocking("[default]Phase 1 Extrusion/L11/L11_Pos5/Assigned Operator Name")[0].value,
]

import collections

print ([item for item, count in collections.Counter(names).items() if count > 0])

```

It returns this, which is good

```auto
[u'Neta Justice', u'Jerome Smith']

```

Is there a way for it to tell me how many names are there?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 27, 2023, 4:32pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/7 "2023-03-27T16:32:22Z")

</div>

First, don't ever issue a whole bunch of separate readBlocking calls in a row like that. It's _terrible_ for performance.  
Second, `collections.Counter().items()` returns an iterable of `(item, count)` tuples. In @dkhayes117's code, that iterable is being used in a list comprehension and simultaneously _unpacked_ into just the `item` return value; that's this line:

```python
[item for item, count in collections.Counter(names).items() if count > 0]

```

If it helps, you can think of that list comprehension as being this imperative loop:

```python
ret = []
for item, count in collections.Counter(names).items():
	if count > 0:
		ret.append(item)

```

So if you wanted to return _both_ the name and the count, you have to decide on a different structural representation. There's a _lot_ of options, but one simple one that allows you to return things with some sort order would be a list of tuples. To sort, you can use the `sorted` builtin; and since you (potentially) want the highest count first, you could add the reverse flag:

```python
sorted(
	itemCount for itemCount in collections.Counter(names).items() if count > 0,
	key=lambda x: x[1],
	reverse=True
)

```

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [March 27, 2023, 4:35pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/8 "2023-03-27T16:35:50Z")

</div>

**system.tag.readBlocking()** works much faster if you use it only once and pass a list into it  
About your Return, if i got it correctly, Counter will return only uniques so in the end you just need to count how many elements are, maybe just adding a len() solves it, basically:

```auto
names = [tag.value for tag in system.tag.readBlocking(["[default]Phase 1 Extrusion/L31/L31_Pos1/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L31/L31_Pos2/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L31/L31_Pos3/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L31/L31_Pos4/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L11/L11_Pos1/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L11/L11_Pos1/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L11/L11_Pos2/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L11/L11_Pos3/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L11/L11_Pos4/Assigned Operator Name",
														  "[default]Phase 1 Extrusion/L11/L11_Pos5/Assigned Operator Name"])]
import collections

print len([item for item, count in collections.Counter(names).items() if count > 0])

```

---

<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 27, 2023, 4:39pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/9 "2023-03-27T16:39:15Z")

</div>

Here is a version that uses the Counter constructor.

Note that your original code has an extra `L11_Pos1` path, I've removed that.

```auto
import collections

paths = ["[default]Phase 1 Extrusion/L31/L31_Pos1/Assigned Operator Name","[default]Phase 1 Extrusion/L31/L31_Pos2/Assigned Operator Name","[default]Phase 1 Extrusion/L31/L31_Pos3/Assigned Operator Name","[default]Phase 1 Extrusion/L31/L31_Pos4/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos1/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos2/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos3/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos4/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos5/Assigned Operator Name"]

cnt = collections.Counter([tag.value for tag in system.tag.readBlocking(paths)])

print cnt

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 4:47pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/10 "2023-03-27T16:47:45Z")

</div>

Thats good to know about the readBlockings, thanks

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 4:48pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/11 "2023-03-27T16:48:28Z")

</div>

Thats correct. thanks.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 4:48pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/12 "2023-03-27T16:48:54Z")

</div>

Thank you sir!

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 27, 2023, 4:58pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/13 "2023-03-27T16:58:02Z")

</div>

You can also get fancy and generate your paths programmatically, since they (in this case) follow a very simple structure:

```python
levels = {"L31": 4, "L11": 5}

ret = [
	"[default]Phase 1 Extrusion/{level}/{level}_Pos{position}/Assigned Operator Name".format(level=level, position=position + 1)
	for level, positions in levels.items()
	for position in xrange(positions)
]
print ret

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 27, 2023, 7:28pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/14 "2023-03-27T19:28:44Z")

</div>

One reason why I do not like to do this is if you (or more problematically) someone else is searching for the full tag path because something is going on in the scripting, it will not appear. Tag paths are one thing I think should always be written out in full but maybe I'm wrong.

---

<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 27, 2023, 7:53pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/15 "2023-03-27T19:53:51Z")

</div>

> [@bkarabinchak.psi](#):
>
> I think should always be written out in full but maybe I'm wrong

There is honestly nothing I loath more than typing 90% of the same string in a list over and over again.

Even here, I copied the original code and deleted the things needed to make it a properly formed list. Generally I would use the approach that @paul-griffith shows.

Perhaps I'm just lazy.

---

<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:** [March 27, 2023, 7:55pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/16 "2023-03-27T19:55:31Z")

</div>

> [@lrose](#):
>
> There is honestly nothing I loath more than typing 90% of the same string in a list over and over again.

With you entirely. The opportunity for typos when repeatedly spelling such things out far outweighs any full path search options.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 8:43pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/17 "2023-03-27T20:43:13Z")

</div>

All this discussion was great, thanks alot guys!

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 9:05pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/18 "2023-03-27T21:05:20Z")

</div>

Is there a way to remove the "u'" before the names: [u'Neta Justice', u'Jerome Smith']

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 27, 2023, 9:11pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/19 "2023-03-27T21:11:06Z")

</div>

That 'u' isn't "real"; it's only there because you're printing a list directly.

```python
l = [u'Neta Justice', u'Jerome Smith']
print l
for name in l:
	print name

```

```auto
>>> 
[u'Neta Justice', u'Jerome Smith']
Neta Justice
Jerome Smith

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [March 27, 2023, 9:12pm UTC](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646/20 "2023-03-27T21:12:04Z")

</div>

> [@lrose](#):
>
> ```auto
> import collections
> 
> paths = ["[default]Phase 1 Extrusion/L31/L31_Pos1/Assigned Operator Name","[default]Phase 1 Extrusion/L31/L31_Pos2/Assigned Operator Name","[default]Phase 1 Extrusion/L31/L31_Pos3/Assigned Operator Name","[default]Phase 1 Extrusion/L31/L31_Pos4/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos1/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos2/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos3/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos4/Assigned Operator Name","[default]Phase 1 Extrusion/L11/L11_Pos5/Assigned Operator Name"]
> 
> cnt = collections.Counter([tag.value for tag in system.tag.readBlocking(paths)])
> 
> print cnt
> 
> ```

Oh, ok, good to know sir. thanks

[Next page](https://forum.inductiveautomation.com/t/quantify-labels-with-names-in-them/71646.md?page=2)
