How to Group Value of List!

How to Group Same Value of List in the Pictute…

Thank You

Read up on how to use GroupByKey

2 Likes

GroupByKey return result not like picture

Thank @Bjorn_Keulemans1

liste = IN[0]

from collections import OrderedDict

unique = list(OrderedDict.fromkeys(liste))
output = []
for i in unique:
	temp = []
	for j in liste:
		if j ==i:
			temp.append(j)
	output.append(temp)

OUT = output
2 Likes

Can group in the picture…?

Thank @Deniz_Maral

group by key node resolves the job, creating a dictionary by keys as well
image

1 Like

@Eng.Minh Try this:

from itertools import groupby
OUT = [list(groups) for keyValue,groups in groupby(IN[0])]
8 Likes

Is the idea to group values that are the same consecutively?
As long as the value is the same it’s in the same list, once it changes you need another list and so on?

1 Like

Thank @AmolShah , it worked fine.

Yes, it is my idea, i need group to count amount of detector and replace by annotation in the picture

@AmolShah
I like your coding skills,
bcoz i got same solution by writing 20-25 lines of code and you got it in 2 line. :slight_smile:

3 Likes