# Increment a mixed list of alphanumeric strings

**URL:** <https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392>\
**Category:** Revit\
**Created:** [July 25, 2020, 8:23pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392 "2020-07-25T20:23:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Peter\_Jenkins](https://forum.dynamobim.com/u/Peter_Jenkins)\
**Post date:** [July 25, 2020, 8:23pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/1 "2020-07-25T20:23:59Z")

</div>

So I have a list that can contain numbers and letters which are strings. On each routine this list needs to be incremented by 1, Example 1-2, 47-48, A-B and G-H. I can get it work by turning strings to numbers, +1 them in a code block then convert back to a string to populate the parameter. I can’t figure out how to do this with letters.  
Has anyone come across something like this before?

---

<div class="post-metadata">

**Author:** ![d.kuurman](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@d.kuurman](https://forum.dynamobim.com/u/d.kuurman)\
**Post date:** [July 25, 2020, 9:19pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/2 "2020-07-25T21:19:47Z")

</div>

> <https://stackoverflow.com/questions/41159541/incrementing-an-alphanumeric-string-in-python>

A bit of googling brought me this. Maybe take a look at it and give it a shot.

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [July 26, 2020, 7:01am UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/3 "2020-07-26T07:01:05Z")

</div>

Hello try this Python script

```
lst_toIncr = IN[0] #input value must be a string's list digit or alpha
out = []
for val in lst_toIncr:
	if val.isdigit():
		out.append(str(int(val) + 1))
	else:
		out.append(chr(ord(val) + 1))

OUT = out
```

---

<div class="post-metadata">

**Author:** ![Vikram\_Subbaiah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vikram_subbaiah/32/50797_2.png) [@Vikram\_Subbaiah](https://forum.dynamobim.com/u/Vikram_Subbaiah)\
**Post date:** [July 26, 2020, 1:56pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/4 "2020-07-26T13:56:13Z")

</div>

> [@Peter\_Jenkins](#):
>
> On each routine this list needs to be incremented by 1,

 ![increment](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/9/39d21099f7bb63bd06f994e635bb15238becbc90.png)

`List.IndexOf("A".."Z",a) == -1 ? String.ToNumber(a) + 1 : List.GetItemAtIndex(List.AddItemToEnd("A","A".."Z") , List.IndexOf("A".."Z",a) + 1);`

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 26, 2020, 5:39pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/5 "2020-07-26T17:39:18Z")

</div>

Might be a bit faster to avoid the lookups, which will also help with mixed cases:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/e/3e2057178f58bd66e77a2730bed22782fbeb59a7.png)

```
vals =
   String.ToNumber(a)==null?
      DSCore.List.LastItem((a..#2..1)<1L>):
      String.ToNumber(a)+1;

```

---

<div class="post-metadata">

**Author:** ![Peter\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Peter\_Jenkins](https://forum.dynamobim.com/u/Peter_Jenkins)\
**Post date:** [July 27, 2020, 4:45pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/6 "2020-07-27T16:45:36Z")

</div>

Cheers for that, this worked for what I need.

---

<div class="post-metadata">

**Author:** ![Peter\_Jenkins](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Peter\_Jenkins](https://forum.dynamobim.com/u/Peter_Jenkins)\
**Post date:** [July 27, 2020, 4:47pm UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/7 "2020-07-27T16:47:21Z")

</div>

Cheers again Jacob, this works on the newer version of Dynamo but this script sometimes has to work on Dynamo 1.3. Ill use this on projects post 2018.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [July 28, 2020, 2:40am UTC](https://forum.dynamobim.com/t/increment-a-mixed-list-of-alphanumeric-strings/53392/8 "2020-07-28T02:40:50Z")

</div>

Ah, the horrors of the old versions. 2017 and up should support 2.0.4 though which might save you some coding time and package management and calculation times. Worth a consideration, but glad you’re sorted out either way. 🙂
