Split list and group by first character

revit
dynamo

#1

Hello,

I have a list of level names as below

L1
L2
L3
L4
B1
B2
B3
B8

How can I split this list to that I get two groups - “L” prefixed and “B” prefixed ones?
Trying to work my head around Group By Key but cannot figure out if it is the correct way of doing it and how it works.

Thank you


#2

Can you show what you have so far?
All it should take is getting the first character then grouping the initial strings by those characters.


#3

String.CharacterAtIndex to get the first character.

List.GroupByKey where the original list of strings is the list, and the keys are results of the character at index node. You can then sort the list of lists by the unique keys if you want the b levels before the L levels.


#4

I think I have also seen a String.StartsWith node somewhere.
It could be useful to first check what’s in the Dictionary about strings:
http://dictionary.dynamobim.com/#/Core/String/Action/StartsWith