# Prefix + List + Suffix in Python

**URL:** <https://forum.inductiveautomation.com/t/prefix-list-suffix-in-python/21629>\
**Category:** Ignition\
**Created:** [January 1, 2019, 12:14am UTC](https://forum.inductiveautomation.com/t/prefix-list-suffix-in-python/21629 "2019-01-01T00:14:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [January 1, 2019, 12:14am UTC](https://forum.inductiveautomation.com/t/prefix-list-suffix-in-python/21629/1 "2019-01-01T00:14:04Z")

</div>

This is a Python question which is not specific to Ignition, but I am using this in a gateway script. I have a script that does exactly what I want but I am guessing there is a more efficient way to code this in Python and welcome any comments. I have a list of 10 alarm tags but I need to append a prefix and suffix for the tag path of each item in the list. The code is:

```auto
#Create list of integers 1-10
IndexList = range(1,11,1)
#Convert integer list to string list
StrIndexList = list(map(str, IndexList))
print StrIndexList
#Add a suffix to each value in the list
AlarmText = '/Alarm'
SuffixList = [SuffixVal + AlarmText for SuffixVal in StrIndexList]
print SuffixList
#Add a prefix to each value in the list
AlmTagList = ["Test_Tags/Alarm" + TextVal for TextVal in SuffixList]
print AlmTagList

```

The results from the print statements are exactly what I want:

```auto
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
['1/Alarm', '2/Alarm', '3/Alarm', '4/Alarm', '5/Alarm', '6/Alarm', '7/Alarm', '8/Alarm', '9/Alarm', '10/Alarm']
['Test_Tags/Alarm1/Alarm', 'Test_Tags/Alarm2/Alarm', 'Test_Tags/Alarm3/Alarm', 'Test_Tags/Alarm4/Alarm', 'Test_Tags/Alarm5/Alarm', 'Test_Tags/Alarm6/Alarm', 'Test_Tags/Alarm7/Alarm', 'Test_Tags/Alarm8/Alarm', 'Test_Tags/Alarm9/Alarm', 'Test_Tags/Alarm10/Alarm']

```

Is there a more concise/efficient way to code this?

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [January 1, 2019, 12:31am UTC](https://forum.inductiveautomation.com/t/prefix-list-suffix-in-python/21629/2 "2019-01-01T00:31:53Z")

</div>

```auto
AlmTagList = ['Test_Tags/Alarm%d/Alarm' % x for x in range(1,11)]

```

---

<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:** [January 1, 2019, 12:32am UTC](https://forum.inductiveautomation.com/t/prefix-list-suffix-in-python/21629/3 "2019-01-01T00:32:06Z")

</div>

Yep.

```auto
AlmTagList = ["Test_Tags/Alarm%d/Alarm" % i for i in range(1,11)]

```

---

<div class="post-metadata">

**Author:** ![pdixon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdixon/32/6899_2.png) [@pdixon](https://forum.inductiveautomation.com/u/pdixon)\
**Post date:** [January 1, 2019, 1:21am UTC](https://forum.inductiveautomation.com/t/prefix-list-suffix-in-python/21629/4 "2019-01-01T01:21:22Z")

</div>

witman and ptumel, much thanks!
