# Get capital letters by condtion

**URL:** <https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498>\
**Category:** Developers\
**Created:** [September 5, 2023, 12:40pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498 "2023-09-05T12:40:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 5, 2023, 12:40pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/1 "2023-09-05T12:40:30Z")

</div>

Hello,

i use already a script, it works partly well

![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/8/58592378020cb679c36975f3c4af78d6d8c5a4c7.png)

can is say something like “get split string if it has 3 capital letters”

so i get just the values GIT,GIP,STB,… ?

these values are not always at the same place!

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/0/909c47070077f7c78cd9424a98400feb8d2ebf05.png)

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Marcel\_Rijsmus](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/marcel_rijsmus/32/8539_2.png) [@Marcel\_Rijsmus](https://forum.dynamobim.com/u/Marcel_Rijsmus)\
**Post date:** [September 5, 2023, 1:04pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/2 "2023-09-05T13:04:39Z")

</div>

Have you tried searching for Fuzzy Logic on the forum?  
I might have some clues

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 5, 2023, 1:06pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/3 "2023-09-05T13:06:56Z")

</div>

@Marcel_Rijsmus ,

> **[Fuzzy String Matching - Dynamo BIM](http://dynamobim.org/fuzzy-string-matching/)**
>
> Anyone who works regularly in Revit has seen just how unorganized naming conventions can get. Work sharing with a handful of people or a dozen people can lead to many …

it leads to you 😉

---

<div class="post-metadata">

**Author:** ![Josip.Komadina](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/josip.komadina/32/168179_2.png) [@Josip.Komadina](https://forum.dynamobim.com/u/Josip.Komadina)\
**Post date:** [September 5, 2023, 1:15pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/4 "2023-09-05T13:15:05Z")

</div>

Hi,

If you just wanna get the 3 capitals in a row this is my logic behind it.  
I am sure it can be made a lot simpler.

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

```auto
input_list = IN[0]
uppers = []

for sent in input_list:
	count_upper = 0
	for i in sent:
		if i.isupper():
			count_upper+=1
		else:
			count_upper = 0
		if count_upper == 3:
			first_two = sent.index(i)
			first = sent[first_two - 2]
			second = sent[first_two - 1]
			third = i
			uppers.append(first+second+third)
			continue
# Assign your output to the OUT variable.
OUT = uppers

```

Hope it helps.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [September 5, 2023, 1:37pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/5 "2023-09-05T13:37:13Z")

</div>

1. Check to see if a substring is all caps by converting it and comparing.
2. Check to see if a substring is 3 characters in length.
3. Filter for substrings that meet both of those requirements.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/1/d12a6eb09c00aa52356805dcc4d7ffe6b60c86e4.png)

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 5, 2023, 1:53pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/6 "2023-09-05T13:53:29Z")

</div>

@Josip.Komadina ,

that works really fine, can exclude symbols like “\_”

thats the only beauty case that i have to avoid!

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/2/828703b2e667313115e2cba5fb1f9261d4961432.png)

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Josip.Komadina](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/josip.komadina/32/168179_2.png) [@Josip.Komadina](https://forum.dynamobim.com/u/Josip.Komadina)\
**Post date:** [September 5, 2023, 1:57pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/7 "2023-09-05T13:57:42Z")

</div>

Weird behaviour.  
Maybe you can just put and isalpha() in the if statement and solve everything.

```auto
input_list = IN[0]
uppers = []

for sent in input_list:
	count_upper = 0
	for i in sent:
		if i.isupper() and i.isalpha():
			count_upper+=1
		else:
			count_upper = 0
		if count_upper == 3:
			first_two = sent.index(i)
			first = sent[first_two - 2]
			second = sent[first_two - 1]
			third = i
			uppers.append(first+second+third)
			continue
# Assign your output to the OUT variable.
OUT = uppers

```

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [September 5, 2023, 2:06pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/8 "2023-09-05T14:06:26Z")

</div>

The count is off because you reset your counter instead of just not adding to it. You also stop as soon as you find 3 consecutive capitals instead of checking to see if the substring is exactly 3 characters long.

Even with python, I still think you need to split and check substrings (if that’s the specific condition you’re looking for, @Draxl_Andreas). This also assumes that there’s only a single 3 character condition in each string.

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 5, 2023, 2:08pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/9 "2023-09-05T14:08:06Z")

</div>

@Nick_Boyts ,

thats right, naming is still not clean, first i have to chang the name of the walls to something like a naming convention.

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [September 5, 2023, 2:10pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/10 "2023-09-05T14:10:50Z")

</div>

Something like this:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/1/712123796d80c0067f26cf84a715dbd7360634af.png)  
If you can ensure you only have one condition you’re looking for per string then you can of course remove the extra loop for sublists.

---

<div class="post-metadata">

**Author:** ![Josip.Komadina](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/josip.komadina/32/168179_2.png) [@Josip.Komadina](https://forum.dynamobim.com/u/Josip.Komadina)\
**Post date:** [September 5, 2023, 2:14pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/11 "2023-09-05T14:14:15Z")

</div>

You are right that it needs to check the entire substring if its not formatted correctly.

My thought process was if you don’t reset the counter it will count the every capital character in the entire string.  
By resetting it you can get exactly 3 in a row.  
My assumption was that you have only 3 uppers in each string that represent something and that you need them.  
Seems to not have problems if you are only looking for 3 upper chars in a string.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [September 5, 2023, 2:18pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/12 "2023-09-05T14:18:28Z")

</div>

> [@Josip.Komadina](#):
>
> By resetting it you can get exactly 3 in a row.  
> My assumption was that you have only 3 uppers in each string that represent something and that you need them.

Nope, I think you’re completely right there. That was my fault. I just lumped that in with the potential under-counting.

This would also be the better process if they weren’t already broken into substrings with the formatting. That just makes things easier.

---

<div class="post-metadata">

**Author:** ![AmolShah](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/amolshah/32/103244_2.png) [@AmolShah](https://forum.dynamobim.com/u/AmolShah)\
**Post date:** [September 5, 2023, 3:39pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/13 "2023-09-05T15:39:20Z")

</div>

@Draxl_Andreas You can do something like this with Regex:

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

```auto
import re
pattern = r'(?<![A-Z])[A-Z]{3}(?![A-Z])'
OUT = [re.findall(pattern,x) for x in IN[0]]

```

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 5, 2023, 3:48pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/14 "2023-09-05T15:48:21Z")

</div>

@AmolShah ,

thats pretty short, and it looks like “chinese” 😉

i lost a bit the track… how to manage the count of the doors(and host)… ?

i try to replace the errors by a “dummy” value

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/5/e56bafbc71dcf8b2821e959c8211e5e50b9d9009.png)  
KR  
Andreas

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [September 5, 2023, 4:31pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/15 "2023-09-05T16:31:24Z")

</div>

That’s just because you have empty lists for cases that don’t match the condition. You can replace them with nulls (or empty strings) if you need to keep list structure _and_ item count.

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 6, 2023, 7:26am UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/16 "2023-09-06T07:26:37Z")

</div>

@AmolShah ,

for any reason it generates more values as input can i also so

```auto
if "_XXX_" # take it 

```

the issue is when there are 3 upper letter in the same string. It does create a new item

 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/e/4eb34b3f092cb72a74705835d04e6306e7a08fcd.png)  
 ![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/c/3cf96f8c85c5df926e433ac8d633e128e5c4f139.png)

can i create something like this?

![grafik](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/0/7050ffda1c25de6e6940f26ea131301dbc0068fd.png)

but it is a progress, it solves 90% of my cases

KR

Andreas

---

<div class="post-metadata">

**Author:** ![Josip.Komadina](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/josip.komadina/32/168179_2.png) [@Josip.Komadina](https://forum.dynamobim.com/u/Josip.Komadina)\
**Post date:** [September 6, 2023, 1:54pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/17 "2023-09-06T13:54:45Z")

</div>

Hi,

Here is how I would do it with my limited knowledge 😄

```auto
import re
pattern = r'(?<![A-Z])[A-Z]{3}(?![A-Z])'
new = [re.findall(pattern,x) for x in IN[0]]

strings = []
empty = ""
for n in new:
	if len(n)>1:
		for i in n:
			empty = empty + "_" +i
		strings.append(empty)
	else:
		strings.append(n[0])
OUT = strings

```

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

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 6, 2023, 1:56pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/18 "2023-09-06T13:56:03Z")

</div>

@Josip.Komadina ,

thats good and easy to detect! i can do it manualy the final 10%

KR

Andreas

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [September 6, 2023, 3:44pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/19 "2023-09-06T15:44:48Z")

</div>

Hi, I also tried limiting myself to capital letters between “_" and "_”

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

```auto

import sys
def spec(a):
    b=a.split("_")
    del(b[0],b[-1])
    c=[b[i] for i in range(len(b)) if b[i].isupper()]
    return c
lst=IN[0]

OUT = [spec(i) for i in lst]

```

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [September 6, 2023, 3:47pm UTC](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498/20 "2023-09-06T15:47:35Z")

</div>

@christian.stan ,

in your version is missing when there are 2 times upcase…

f. e. “bla\_bla\_CAR\_bla\_bla\_DOG” → CAR\_DOG

KR

Andreas

[Next page](https://forum.dynamobim.com/t/get-capital-letters-by-condtion/93498.md?page=2)
