# Remove numbers from a list but keep all characters

**URL:** <https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025>\
**Category:** Packages\
**Tags:** dynamo\
**Created:** [November 11, 2019, 5:14pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025 "2019-11-11T17:14:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zalgirietis.minde](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zalgirietis.minde](https://forum.dynamobim.com/u/zalgirietis.minde)\
**Post date:** [November 11, 2019, 5:14pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025/1 "2019-11-11T17:14:22Z")

</div>

Hi all!

I was scrolling down through the forum but I could’t find the right solution.

I have a list and I’m looking for a script that helps to remove numbers 0…9, but keep everything else.  
For ex.:

List:  
NE-NEX-Z-W01  
NE-NEX-Z-W02  
.  
.  
NE-NEX-Z-W101

The output suppose to be:

NE-NEX-Z-W  
NE-NEX-Z-W  
.  
.  
NE-NEX-Z-W

I found some good scripts how to extract only numbers but I can’t figure this out .

This one works fine for extracting numbers:

```
output = []
    for x in IN[0]:
       output.append(float(filter(str.isdigit, x)))
    OUT = output

```

\*Note that removing characters from left to right is not an option because the amount of characters may vary.

Please share your ideas. Thanks!

---

<div class="post-metadata">

**Author:** ![Thomas\_Corrie](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_corrie/32/63060_2.png) [@Thomas\_Corrie](https://forum.dynamobim.com/u/Thomas_Corrie)\
**Post date:** [November 11, 2019, 5:27pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025/2 "2019-11-11T17:27:34Z")

</div>

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/4/54f31195d8763cce313e0eb578ab9bf5507bfeac.png)

```
output = []
for x in IN[0]:
	output.append(filter(lambda v: not str.isdigit(v), x))
OUT = output
```

---

<div class="post-metadata">

**Author:** ![Brendan\_Cassidy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/brendan_cassidy/32/7685_2.png) [@Brendan\_Cassidy](https://forum.dynamobim.com/u/Brendan_Cassidy)\
**Post date:** [November 11, 2019, 5:28pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025/3 "2019-11-11T17:28:09Z")

</div>

Utilise the following should help sort your issue, but do watch out that it will remove all numbers no matter where they are in your string.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/2/921c1bbcc9b9c4dcd607c523ab20b27dd66e2c98.png)

---

<div class="post-metadata">

**Author:** ![zalgirietis.minde](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zalgirietis.minde](https://forum.dynamobim.com/u/zalgirietis.minde)\
**Post date:** [November 11, 2019, 5:31pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025/4 "2019-11-11T17:31:30Z")

</div>

That’s exactly what I was looking for! Thanks.

---

<div class="post-metadata">

**Author:** ![zalgirietis.minde](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@zalgirietis.minde](https://forum.dynamobim.com/u/zalgirietis.minde)\
**Post date:** [November 11, 2019, 5:32pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025/5 "2019-11-11T17:32:47Z")

</div>

I really appreciate for a quick answer. Numbers will be 100% at the end of the string so I don’t need to worry about. Thanks!

---

<div class="post-metadata">

**Author:** ![Brendan\_Cassidy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/brendan_cassidy/32/7685_2.png) [@Brendan\_Cassidy](https://forum.dynamobim.com/u/Brendan_Cassidy)\
**Post date:** [November 11, 2019, 5:37pm UTC](https://forum.dynamobim.com/t/remove-numbers-from-a-list-but-keep-all-characters/43025/6 "2019-11-11T17:37:05Z")

</div>

If you could end up with numbers any where else that you will need to keep within then use the following code. If the numbers will always be at the end then either mine or @Thomas_Corrie solution will work perfectly 🙂

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

Code:

```
output=[]
for a in IN[0]:
	newlist = a.split("-")
	stringpos = 0
	for sp in newlist[:-1]:
		stringpos = stringpos + len(sp)
	stringpos = stringpos + len(newlist[:-1])
	templist=[]
	for i, c in enumerate(newlist[-1]):
		if c.isdigit():
			templist.append(i)
	output.append(a[0:(stringpos+min(templist))])
OUT=output

```

Edited: updated image and code to something more robust.
